QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133768#4934. Forbidden Cardwhsyhyyh#RE 0ms0kbC++141.0kb2023-08-02 13:57:442023-08-02 13:57:47

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:57:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-02 13:57:44]
  • 提交

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;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

3 6
1 2
2 4
4 2

output:


result: