QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133768 | #4934. Forbidden Card | whsyhyyh# | RE | 0ms | 0kb | C++14 | 1.0kb | 2023-08-02 13:57:44 | 2023-08-02 13:57:47 |
Judging History
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(){
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
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]]&&!flag) 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]=min(ys,i);
else f[i]=f[mp[c[i].par]];
mp[c[i].x]=i;
}
for(int i=1;i<=m;i++){
if(!mp[i]) ans[c[ys].id]++;
else ans[c[min(f[mp[i]],ys)].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: 0
Dangerous Syscalls
input:
3 6 1 2 2 4 4 2