QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133722#4934. Forbidden Cardwhsyhyyh#WA 151ms31032kbC++141001b2023-08-02 13:30:552023-08-02 13:30:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 13:30:58]
  • 评测
  • 测评结果:WA
  • 用时:151ms
  • 内存:31032kb
  • [2023-08-02 13:30:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+9;
int n,m,a[N],b[N],f[N],ans[N];
map<int ,int >mp;
struct pp{int id,x,par,nxt;}c[N];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++){
		if(mp[a[i]]) swap(a[i],b[i]);
		mp[a[i]]=1;
	}
	for(int i=1;i<=n;i++) c[i].x=a[i],c[i].id=i;
	for(int i=1;i<=n;i++) c[i+n].x=b[i],c[i+n].id=i;
	
//	for(int i=1;i<=n*2+1;i++) printf("%d ",c[i].x);puts("");
	
	c[2*n+1].id=1;
	int ys=2*n+1;mp.clear();
	int flag=0;
	for(int i=1;i<=2*n;i++){
		if(mp[c[i].x]&&ys==2*n+1){
			ys=i;
			flag=1;
		}
		mp[c[i].x]=1;
		if(!mp[b[i]]) c[i].par=b[i];
		else c[i].par=0;
	}
	mp.clear();
	for(int i=2*n;i>=1;i--){
		if(!c[i].par) f[i]=i;
		else f[i]=f[mp[c[i].par]];
		if(f[i]>=ys) f[i]=min(ys,i);
		mp[c[i].x]=i;
	}
	for(int i=1;i<=m;i++){
		if(!mp[i]) ans[c[ys].id]++;
		else ans[c[f[mp[i]]].id]++;
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 6
1 2
2 4
4 2

output:

3
0
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 11820kb

input:

4 10
1 5
2 6
3 7
4 8

output:

4
2
2
2

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 11844kb

input:

1 2
1 2

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 151ms
memory: 31032kb

input:

69332 250102
51362 228823
206751 31351
181790 44202
186695 92215
172072 173179
86663 76959
42382 25827
204750 30001
42502 11959
201030 71886
227497 216114
164282 235028
178967 181951
125356 20611
169528 174071
50985 175562
63676 208400
189134 229462
49746 131529
180236 247427
29278 229589
30381 4412...

output:

180770
1
1
1
1
1
0
1
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
0
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
0
0
1
1
1
1
1
1
1
1
0
1
1
0
0
0
0
1
1
1
1
0
0
0
1
1
1
0
1
1
1
0
1
0
0
1
0
1
0
1
1
0
1
1
0
1
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
0...

result:

wrong answer 1st lines differ - expected: '197458', found: '180770'