牛客练习赛13F m皇后

时间:2023-03-09 18:15:31
牛客练习赛13F m皇后

题目链接:https://ac.nowcoder.com/acm/contest/70/F

题目大意:

  略

分析:

  可以分成四步计算冲突:水平方向,垂直方向,左斜线方向,右斜线方向。只要会处理水平方向,其余同理。

代码如下:

 #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std; #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define SORT(c, s, t) sort(c + s, c + t + 1) #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef set< int > SI;
typedef vector< int > VI;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ; struct Queen{
int r, c, cnt = ;
}; // 先按行排序,再按列排序
inline bool cmp1(const Queen &x, const Queen &y) {
if(x.r == y.r) return x.c < y.c;
return x.r < y.r;
} // 先按列排序,再按行排序
inline bool cmp2(const Queen &x, const Queen &y) {
if(x.c == y.c) return x.r < y.r;
return x.c < y.c;
} // 先按r - c排序,再按r + c排序
inline bool cmp3(const Queen &x, const Queen &y) {
if(x.r - x.c == y.r - y.c) return x.r + x.c < y.r + y.c;
return x.r - x.c < y.r - y.c;
} // 先按r + c排序,再按r - c排序
inline bool cmp4(const Queen &x, const Queen &y) {
if(x.r + x.c == y.r + y.c) return x.r - x.c < y.r - y.c;
return x.r + x.c < y.r + y.c;
} // 行方向计数辅助函数
inline bool cnt1(const Queen &x, const Queen &y) {
return x.r == y.r;
} // 列方向计数辅助函数
inline bool cnt2(const Queen &x, const Queen &y) {
return x.c == y.c;
} // 左斜线方向计数辅助函数
inline bool cnt3(const Queen &x, const Queen &y) {
return x.r - x.c == y.r - y.c;
} // 右斜线方向计数辅助函数
inline bool cnt4(const Queen &x, const Queen &y) {
return x.r + x.c == y.r + y.c;
} int n, m;
Queen Q[maxN];
int ans[]; // 方向计数函数
void CountDir(bool (*fcnt)(const Queen&,const Queen&)) {
//cout << endl;
//For(i, 1, m) cout << MP(Q[i].r, Q[i].c);
int cnt = ;
For(i, , m) {
if(fcnt(Q[i], Q[i - ])) {
if(cnt == ) Q[i - ].cnt += ;
else Q[i - ].cnt += ;
++cnt;
}
else {
if(cnt > )Q[i - ].cnt += ;
cnt = ;
}
}
if(cnt > ) Q[m].cnt += ;
//For(i, 1, m) cout << Q[i].cnt << " ";
//cout << endl;
} int main(){
INIT();
cin >> n >> m;
For(i, , m) cin >> Q[i].r >> Q[i].c; // 处理左右
sort(Q + , Q + m + , cmp1);
CountDir(cnt1);
// 处理上下
sort(Q + , Q + m + , cmp2);
CountDir(cnt2);
// 处理左上,左下
sort(Q + , Q + m + , cmp3);
CountDir(cnt3);
// 处理右上,右下
sort(Q + , Q + m + , cmp4);
CountDir(cnt4); For(i, , m) ++ans[Q[i].cnt];
Rep(i, ) cout << ans[i] << " ";
cout << endl;
return ;
}