QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234155 | #4934. Forbidden Card | fansizhe | RE | 0ms | 0kb | C++14 | 1.0kb | 2023-11-01 14:36:31 | 2023-11-01 14:36:31 |
answer
#include<bits/stdc++.h>
using namespace std;
int read(){
int x=0;char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')x=x*10+(c^'0'),c=getchar();
return x;
}
int n,m;
int a[200005],b[200005];
int vis[1000005],num[1000005];
int ans[200005];
int main(){
freopen("marketplace.in","r",stdin);
freopen("marketplace.out","w",stdout);
n=read(),m=read();
for(int i=1;i<=n;i++)a[i]=read(),b[i]=read();
for(int i=n+1;i<=2*n;i++)a[i]=a[i-n],b[i]=b[i-n];
a[2*n+1]=a[1],b[2*n+1]=b[1];
for(int i=1;i<=m;i++)num[i]=1;
int now=m;
for(int i=1;i<=2*n+1;i++){
if(!vis[a[i]]){
vis[a[i]]=1;
if(vis[b[i]])ans[i]=num[a[i]],now-=num[a[i]];
else num[b[i]]+=num[a[i]];
}else if(!vis[b[i]]){
vis[b[i]]=1;
ans[i]=num[b[i]],now-=num[b[i]];
}else{ans[i]=now;break;}
}
printf("%d\n",ans[1]+ans[n+1]+ans[2*n+1]);
for(int i=2;i<=n;i++)printf("%d\n",ans[i]+ans[n+i]);
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
3 6 1 2 2 4 4 2