QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120255#6136. Airdropchenxinyang2006AC ✓171ms5940kbC++142.6kb2023-07-06 15:51:392023-07-06 15:51:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 15:51:40]
  • 评测
  • 测评结果:AC
  • 用时:171ms
  • 内存:5940kb
  • [2023-07-06 15:51:39]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int T,n,insty;
pii P[100005];
int buc[200005],res[2][100005];

#define mx 100000
void solve(){
	scanf("%d%d",&n,&insty);
	rep(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		P[i] = mkp(x,abs(y - insty));
	}
	sort(P + 1,P + n + 1);
	fill(res[0],res[0] + n + 2,0);
	fill(res[1],res[1] + n + 2,0);
	int cur = 0,pos;
	for(int l = 1,r;l <= n;l = r + 1){
		r = l;
		while(r < n && P[r + 1].first == P[r].first) r++;

		rep(i,l,r){
			pos = mx - P[i].first + P[i].second;
			if(i != r && P[i].second == P[i + 1].second){
				cur -= buc[pos];
				buc[pos] = 0;
				i++;
				continue;
			}
			cur -= buc[pos];
			buc[pos] ^= 1;
			cur += buc[pos];
		}
		res[0][r] = cur;
	}
	rep(i,1,n) buc[mx - P[i].first + P[i].second] = 0;

	cur = 0;
	for(int r = n,l;r;r = l - 1){
		l = r;
		while(l > 1 && P[l - 1].first == P[l].first) l--;

		rep(i,l,r){
			pos = P[i].first + P[i].second;
			if(i != r && P[i].second == P[i + 1].second){
				cur -= buc[pos];
				buc[pos] = 0;
				i++;
				continue;
			}
			cur -= buc[pos];
			buc[pos] ^= 1;
			cur += buc[pos];
		}
		res[1][l] = cur;
	}
	rep(i,1,n) buc[P[i].first + P[i].second] = 0;

	int Mn = inf,Mx = 0;
	for(int l = 1,r;l <= n;l = r + 1){
		r = l;
		while(r < n && P[r].first == P[r + 1].first) r++;
		chkmin(Mn,r - l + 1 + res[0][l - 1] + res[1][r + 1]);
		chkmax(Mx,r - l + 1 + res[0][l - 1] + res[1][r + 1]);
	}
	P[n + 1] = mkp(inf,0);P[0] = mkp(-inf,0);
	rep(i,0,n){
		if(P[i + 1].first > P[i].first + 1){
			chkmin(Mn,res[0][i] + res[1][i + 1]);
			chkmax(Mx,res[0][i] + res[1][i + 1]);
		}
	}
	printf("%d %d\n",Mn,Mx);
}

int main(){
//	freopen("test.in","r",stdin);
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

input:

3
3 2
1 2
2 1
3 5
3 3
2 1
2 5
4 3
2 3
1 3
4 3

output:

1 3
0 3
2 2

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 171ms
memory: 5940kb

input:

3508
6 1
7 1
1 1
9 1
10 1
3 1
4 1
3 8
8 9
8 7
1 8
9 5
10 1
10 8
10 2
5 1
9 9
5 9
10 9
6 4
4 7
6 7
10 5
3 8
9 5
9 9
7 5
4 7
10 5
6 9
9 5
6 6
9 3
3 2
5 1
3 8
6 4
5 9
10 2
2 9
10 10
10 8
4 1
7 1
6 1
3 1
5 1
2 4
9 3
3 3
4 5
3 8
9 6
9 9
6 3
9 5
9 3
2 9
9 1
9 2
4 1
5 4
5 6
6 5
9 8
4 1
2 1
5 1
7 1
3 1
9 10...

output:

6 6
1 3
1 5
2 6
2 6
0 2
4 4
2 2
4 4
4 7
4 4
9 9
4 6
0 3
2 6
2 2
2 6
10 10
9 9
1 3
2 4
0 2
2 4
4 7
6 6
9 9
2 2
2 2
3 5
1 4
2 2
1 1
3 5
4 7
3 6
1 1
5 7
5 5
1 3
2 2
1 7
1 1
4 6
2 4
2 6
2 4
1 7
2 4
9 9
0 3
1 1
3 8
2 2
2 2
9 9
3 7
4 4
4 6
2 5
0 2
2 5
3 3
0 4
4 4
2 4
2 2
4 6
6 6
6 6
0 2
2 6
2 4
2 6
2 5
1 ...

result:

ok 7016 numbers