QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480775#7245. Frank SinatraluanyanjiaWA 1ms8452kbC++142.0kb2024-07-16 18:46:082024-07-16 18:46:08

Judging History

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

  • [2024-07-16 18:46:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8452kb
  • [2024-07-16 18:46:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline void rd(){}
template<typename T,typename ...U>
inline void rd(T &x,U &...args){
	char ch=getchar();
	T f=1;x=0;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x*=f;rd(args...);          
}
const int N=1e5+5;
int n,Q,fst[N],nxt[N<<1],v[N<<1],w[N<<1],idx;
inline void Add(int a,int b,int c){
	v[idx]=b,nxt[idx]=fst[a];
	w[idx]=c,fst[a]=idx++;
}
int a[N<<2],m,B,b[N<<2],dep[N],st[N],ed[N],fdfn[N];
void DFS(int x,int fa){
	a[++m]=x;
	st[x]=m;
	for(int i=fst[x];~i;i=nxt[i]){
		int y=v[i];
		if(y==fa)continue;
		b[y]=w[i];dep[y]=dep[x]+1; 
		DFS(y,x);
		a[++m]=x;
	}
	ed[x]=m;
}
struct node{int l,r,id;}q[N];
int vis[N],app[N],cnt[N],k[N],ans[N],idv[N];
inline void Ins(int x){
	int d=dep[a[x]]<dep[a[x-1]]?a[x-1]:a[x];
	int val=b[d];
	if(val>=n)return ;
	if(vis[d])cnt[val]--;
	else cnt[val]++;
	if(cnt[val]==1)app[val]=1,k[idv[val]]++;
	else if(!cnt[val])app[val]=0,k[idv[val]]--;
	vis[d]^=1;
}
signed main(){
	memset(fst,-1,sizeof fst);
	rd(n,Q);
	for(int i=1;i<n;i++){
		int x,y,z;rd(x,y,z);
		Add(x,y,z);Add(y,x,z);
	}
	DFS(1,1);
	B=sqrt(m);
	for(int i=1;i<=m;i++)idv[i]=(i-1)/B+1;
	for(int i=1;i<=Q;i++){
		rd(q[i].l,q[i].r),q[i].id=i;
		if(st[q[i].l]>st[q[i].r])swap(q[i].l,q[i].r);
		q[i].l=st[q[i].l],q[i].r=st[q[i].r];
	}
	sort(q+1,q+Q+1,[](node a,node b){
		return idv[a.l]==idv[b.l]?((idv[a.l]&1)?a.r<b.r:a.r>b.r):a.l<b.l;});
	int l=1,r=1;
//	for(int i=1;i<=m;i++)printf("%d ",a[i]);
//	printf("\n");
	for(int i=1;i<=Q;i++){
//		printf("%d %d %d %d %d\n",l,r,q[i].l,q[i].r,q[i].id);
		while(r<q[i].r)Ins(++r);
		while(l>q[i].l)Ins(l--);
		while(r>q[i].r)Ins(r--);
		while(l<q[i].l)Ins(++l);
		if(!k[0])continue;
		for(int x=1;x<=idv[n];x++){
			if(k[x]!=B){
				for(int j=(x-1)*B+1;j<=x*B;j++)
					if(!app[j]){ans[q[i].id]=j;break;}
				break;	
			}
		}
	}
	for(int i=1;i<=Q;i++)printf("%d\n",ans[i]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8452kb

input:

7 6
2 1 1
3 1 2
1 4 0
4 5 1
5 6 3
5 7 4
1 3
4 1
2 4
2 5
3 5
3 7

output:

0
1
2
2
3
3

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 8388kb

input:

2 4
1 2 0
1 1
1 2
2 1
2 2

output:

0
1
1
0

result:

ok 4 number(s): "0 1 1 0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 8368kb

input:

10 100
3 7 1
3 1 0
6 1 1
1 9 0
4 1 1
5 8 1
10 6 0
1 2 1
5 3 1
6 1
4 10
6 5
3 3
5 8
9 2
1 3
8 4
8 5
10 10
5 2
7 10
2 10
8 9
5 3
9 4
6 2
1 8
4 7
3 9
2 5
3 7
10 7
2 2
6 6
6 7
1 9
7 8
6 8
7 3
5 10
5 1
1 2
10 8
8 7
4 2
2 3
7 6
2 9
5 4
10 3
2 4
10 6
3 6
7 4
5 6
10 4
8 2
1 4
9 10
7 9
3 5
9 8
7 2
1 1
7 1
7 ...

output:

0
2
2
1
2
2
1
2
2
1
2
2
2
2
2
2
0
2
2
1
2
2
2
0
1
2
1
2
2
2
2
2
0
2
2
0
2
2
2
2
2
0
1
2
2
2
2
2
0
2
2
2
2
2
0
2
1
2
1
2
2
2
2
2
1
2
2
1
2
0
0
2
2
1
2
2
2
2
2
0
2
2
2
2
2
0
0
1
0
1
2
0
2
2
1
2
2
2
2
2

result:

wrong answer 4th numbers differ - expected: '0', found: '1'