QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#144691#6136. AirdropPhantomThreshold#AC ✓532ms13904kbC++202.7kb2023-08-21 17:50:592023-08-21 17:51:01

Judging History

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

  • [2023-08-21 17:51:01]
  • 评测
  • 测评结果:AC
  • 用时:532ms
  • 内存:13904kb
  • [2023-08-21 17:50:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int INF=1e7;
const int maxn=200000;

int T,n,Y;
pair<int,int> a[maxn+50];
int v[maxn+50];
int cnt[maxn+50];
int pre[maxn+50];
int suf[maxn+50];
bool notok[maxn+50];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> T;
	for (;T--;){
		cin >> n >> Y;
		for (int i=1;i<=n;i++){
			cin >> a[i].first >> a[i].second;
			a[i].second-=Y;
		}
		sort(a+1,a+n+1);
		
		{
			set<pair<int,int>> s;
			for (int i=1;i<=n;i++) s.insert(a[i]);
			
			for (int i=1;i<=n;i++){
				if (a[i].second==0) continue;
				if (s.count(make_pair(a[i].first,-a[i].second))) notok[i]=1;
			}
		}
		
		map<int,int> dict;
		for (int i=1;i<=n;i++) dict[a[i].first]++;
		
		int tot=0;
		for (auto [x,y]:dict){
			++tot;
			v[tot]=x;
			cnt[tot]=y;
		}
		v[0]=-INF;v[tot+1]=INF;
		/*
		cerr << "--------------" << endl;
		for (int i=1;i<=n;i++){
			cerr << "(" << a[i].first << "," << a[i].second << ")" << endl;
		}
		cerr << "tot : " << tot << endl;
		cerr << "v[] : ";
		for (int i=1;i<=tot;i++) cerr << v[i] << " ";
		cerr << endl;
		cerr << "cnt[] : ";
		for (int i=1;i<=tot;i++) cerr << cnt[i] << " ";
		cerr << endl;
		*/
		{
			set<int> s;
			int l=1,r=1;
			for (int sel=1;sel<=n;sel++){
				for (r=l;r<=n && a[r].first==v[sel];r++);
				for (int i=l;i<r;i++){
					int now=abs(a[i].second)-a[i].first;
					if (notok[i]){
						if (s.count(now)) s.erase(now);
					}
					else{
						if (s.count(now)) s.erase(now);
						else s.insert(now);	
					}
				}
				pre[sel]=(int)s.size();
				l=r;
			}
		}
		{
			set<int> s;
			int l=n,r=n;
			for (int sel=n;sel>=1;sel--){
				for (l=r;l>=1 && a[l].first==v[sel];l--);
				for (int i=r;i>l;i--){
					int now=abs(a[i].second)+a[i].first;
					if (notok[i]){
						if (s.count(now)) s.erase(now);
					}
					else{
						if (s.count(now)) s.erase(now);
						else s.insert(now);	
					}
				}
				suf[sel]=(int)s.size();
				r=l;
			}
		}
		
		int mnans=INF,mxans=0;
		for (int i=1;i<=tot;i++){
			int now=pre[i-1]+cnt[i]+suf[i+1];
			mnans=min(mnans,now);
			mxans=max(mxans,now);		
		}
		for (int i=1;i<=tot+1;i++){
			if (v[i]==v[i-1]+1) continue;
			int now=pre[i-1]+suf[i];
			mnans=min(mnans,now);
			mxans=max(mxans,now);		
		}
		/*
		cerr << "pre[] : ";
		for (int i=1;i<=tot;i++) cerr << pre[i] << " ";
		cerr << endl;
		cerr << "suf[] : ";
		for (int i=1;i<=tot;i++) cerr << suf[i] << " ";
		cerr << endl;
		
		cout << "mnans,mxans : ";
		*/
		cout << mnans << " " << mxans << "\n";
		for (int i=0;i<=tot+1;i++){
			v[i]=cnt[i]=0;
			pre[i]=suf[i]=0;
		}
		for (int i=1;i<=n;i++){
			notok[i]=0;	
		}
	}
	return 0;	
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7560kb

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: 532ms
memory: 13904kb

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