QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#82406#4891. 树上的孤独lzqy_0 32ms118700kbC++145.2kb2023-02-27 19:58:052023-02-27 19:58:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-27 19:58:06]
  • 评测
  • 测评结果:0
  • 用时:32ms
  • 内存:118700kb
  • [2023-02-27 19:58:05]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
using namespace std;
const int inf=1<<30;
const int maxn=200010;
const int N=maxn*30;
il int read(){
	int x=0;
	char c=getchar();
	for(;!(c>='0'&&c<='9');c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+c-'0';
	return x;
}
il void chkmax(int &x,int y){if(y>x)x=y;}
struct edge{
	int v,to;
}e[maxn<<1];
int head[maxn],ecnt;
void addedge(int u,int v){
	e[++ecnt].v=v,e[ecnt].to=head[u],head[u]=ecnt;
} 
int n,m,q,cnt1,cnt2,idx,V;
int c1[maxn],c2[maxn];
int dep[maxn],fa[maxn],sz[maxn];
int faa[maxn],depp[maxn];
set<pair<int,int> >s[maxn];
vector<int>v[maxn],f[maxn][20];
vector<int>c[maxn];
int rt1[maxn],d1[N];
int rt2[maxn],d2[N];
int ls1[N],rs1[N];
int ls2[N],rs2[N];
int st[maxn],top;
int dfn[maxn],X; 
bool vis[maxn];
il bool cmp(int x,int y){return dfn[x]<dfn[y];}
il void copy1(int x,int y){
	ls1[x]=ls1[y],rs1[x]=rs1[y],d1[x]=d1[y];
}il void copy2(int x,int y){
	ls2[x]=ls2[y],rs2[x]=rs2[y],d2[x]=d2[y];
}
void A(int &i,int l,int r,int x){
	if(!i) i=++cnt1;
	if(l==r) return d1[i]++,void();
	int mid=l+r>>1;
	if(mid>=x) A(ls1[i],l,mid,x);
	else A(rs1[i],mid+1,r,x);
	d1[i]=d1[ls1[i]]+d1[rs1[i]]; 
}
void A2(int &i,int l,int r,int x,int k){
	if(!i) i=++cnt2;
	if(l==r) return d2[i]=k,void();
	int mid=l+r>>1;
	if(mid>=x) A2(ls2[i],l,mid,x,k);
	else A2(rs2[i],mid+1,r,x,k);
	d2[i]=min(d2[ls2[i]],d2[rs2[i]]);
}
void D(int &i,int l,int r,int x){
	if(!i) i=++cnt1;
	if(l==r) return d1[i]--,void();
	int mid=l+r>>1;
	if(mid>=x) D(ls1[i],l,mid,x);
	else D(rs1[i],mid+1,r,x);
	d1[i]=d1[ls1[i]]+d1[rs1[i]]; 
}
int Q(int i,int l,int r,int L,int R){
	if(l>=L&&r<=R) return d1[i];
		if(l>R||r<L) return 0;
	int mid=l+r>>1;
	return Q(ls1[i],l,mid,L,R)+Q(rs1[i],mid+1,r,L,R);
}
int Q2(int i,int l,int r,int x){
	if(!i) return inf;
	if(l==r) return d2[i];
	int mid=l+r>>1;
	if(mid>=x) return Q2(ls2[i],l,mid,x);
	else return Q2(rs2[i],mid+1,r,x); 
}
int merge1(int a,int b,int l,int r){
	if(!a||!b) return copy1(++cnt1,a|b),cnt1;
	if(l==r) return d1[a]+=d1[b],a;
	int newi=++cnt1,mid=l+r>>1;
	ls1[newi]=merge1(ls1[a],ls1[b],l,mid);
	rs1[newi]=merge1(rs1[a],rs1[b],mid+1,r);
	d1[newi]=d1[ls1[newi]]+d1[rs1[newi]];
//	assert(d1[a]>=0);
	return newi;
}
int merge2(int a,int b,int l,int r,int t,int h){
	if(!a||!b) return copy2(++cnt2,a|b),cnt2;
	if(l==r){
		if(!d2[a]||!d2[b]) return d2[a]=d2[a]|d2[b],a;
		if(d2[a]>d2[b]) D(rt1[t],1,m,d2[a]);
		else D(rt1[t],1,m,d2[b]);
		return d2[a]=min(d2[a],d2[b]),a;
	}int mid=l+r>>1,newi=++cnt2;
	ls2[newi]=merge2(ls2[a],ls2[b],l,mid,t,h);
	rs2[newi]=merge2(rs2[a],rs2[b],mid+1,r,t,h);
	d2[newi]=min(d2[ls2[newi]],d2[rs2[newi]]);
	return newi;
}
void dfs(int fath,int x){
	fa[x]=fath,dep[x]=dep[fa[x]]+1;
	dfn[x]=++idx,sz[x]=1;
	A(rt1[x],1,m,dep[x]);
	A2(rt2[x],1,V,c2[x],dep[x]);
	for(int i=head[x];i;i=e[i].to)
		if(e[i].v^fa[x]) dfs(x,e[i].v),rt2[x]=merge2(rt2[x],rt2[e[i].v],1,V,x,e[i].v);
	for(int i=head[x];i;i=e[i].to)
		if(e[i].v^fa[x]) sz[x]+=sz[e[i].v],rt1[x]=merge1(rt1[x],rt1[e[i].v],1,m);
} 
void init2(int fath,int x){
	faa[x]=fath,depp[x]=depp[fath]+1;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]^fath) init2(x,v[x][i]);
}
void dfs2(int x,int D){
	if(depp[x]>D) return ;
	if(!vis[c1[x]]) st[++top]=c1[x],vis[c1[x]]=1;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]^faa[x]) dfs2(v[x][i],D); 
}
int Mn(int t,int l,int r){
	int Log=log2(r-l+1);
	return min(f[t][Log][l],f[t][Log][r-(1<<Log)+1]);
}
bool chk(int col,int x,int d){
	if(c[col].empty()) return 1;
	int L,R; 
	int l=0,r=c[col].size()-1,mid;
	while(r>l){
		mid=l+r>>1;
		if(dfn[c[col][mid]]>=dfn[x]) r=mid;
		else l=mid+1;
	}
	if(dfn[c[col][l]]<dfn[x]) return 1;
	L=l,r=c[col].size()-1;
	while(r>l){
		mid=l+r+1>>1;
		if(dfn[c[col][mid]]<=dfn[x]+sz[x]-1) l=mid;
		else r=mid-1;
	}
	if(dfn[c[col][l]]>dfn[x]+sz[x]-1) return 1;;
	R=l;
	if(R<L) return 1;
	if(Mn(col,L,R)>dep[x]+d) return 1;
	return 0;
}
int main(){
//	freopen("tree.in","r",stdin);
//	freopen("tree.out","w",stdout);
	n=read(),m=read(),q=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<m;i++){
		int x=read(),y=read();
		addedge(x,y),addedge(y,x);
	}
	for(int i=1;i<=n;i++) c1[i]=read(),chkmax(V,c1[i]);
	for(int i=1;i<=m;i++) c2[i]=read(),chkmax(V,c2[i]);
	dfs(0,1),init2(0,1);
	for(int i=1;i<=m;i++) c[c2[i]].push_back(i);
	for(int i=1;i<=V;i++) sort(c[i].begin(),c[i].end(),cmp);
	for(int i=1;i<=V;i++)
		for(int j=0;j<c[i].size();j++){
			f[i][0].push_back(dep[c[i][j]]);
			for(int k=1;k<20;k++)
				f[i][k].push_back(0);
		}
	for(int t=1;t<=V;t++)
		for(int j=1;j<20;j++)
			for(int i=0;i+(1<<j)-1<c[t].size();i++)
				f[t][j][i]=min(f[t][j-1][i],f[t][j-1][i+(1<<j-1)]);
	int opt,P1,P2,P3,P4,lt=0,ans;
//	q=5;
	while(q--){
		opt=read();
		if(opt==1){
			P1=read(),P2=read();
			P3=read(),P4=read();
			P3^=lt,P4^=lt;
			ans=Q(rt1[P2],1,m,dep[P2],min(m,dep[P2]+P4));
			top=0,dfs2(P1,depp[P1]+P3);
//			printf("!!!!!%d\n",ans);
			for(int i=1;i<=top;i++)
				ans+=chk(st[i],P2,P4),vis[st[i]]=0;
			printf("%d\n",lt=ans);
		}
		else{
			P1=read(),P2=read();
			c1[P1]=P2;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 32ms
memory: 118700kb

input:

20 2000 2000
8 15
8 13
14 8
14 7
12 14
12 1
9 13
9 4
5 9
5 10
2 5
2 19
6 19
6 16
11 7
11 20
18 2
18 17
3 6
1395 1783
1395 1735
1735 457
457 739
739 438
438 101
101 441
441 1879
1879 1238
1238 501
501 1732
1732 1910
1910 2000
2000 834
834 917
917 111
111 780
780 1966
1966 1604
1604 623
623 1748
1748 ...

output:

105
93
2
44
19
54
192
25
69
21
21
200
78
88
137
33
68
68
54
35
24
8
23
78
59
100
27
200
40
74
97
21
87
36
197
76
28
49
11
20
55
60
24
5
109
158
23
21
15
102
36
108
26
78
171
82
32
147
145
9
136
31
109
142
119
68
34
64
18
40
56
48
54
14
35
154
111
130
144
200
21
80
84
37
73
24
28
37
160
51
62
51
95
2...

result:

wrong answer 181st numbers differ - expected: '15', found: '16'

Subtask #2:

score: 0
Runtime Error

Test #3:

score: 0
Runtime Error

input:

20 200000 500000
8 18
8 4
2 4
2 14
13 4
13 16
6 4
6 3
1 4
1 17
15 6
15 19
7 17
7 11
5 14
5 10
20 7
12 15
9 8
165302 77239
165302 198189
165302 180850
165302 192738
165302 173589
165302 194087
165302 191990
165302 167370
165302 101092
165302 92553
165302 163654
165302 122381
165302 152105
165302 1919...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #7:

score: 0
Runtime Error

input:

20 100000 100000
16 12
16 20
6 12
6 18
2 16
2 8
5 20
5 13
3 6
3 11
19 11
19 17
9 12
9 15
4 15
4 7
10 5
14 15
14 1
85812 94626
85812 91172
91172 93788
93788 96567
96567 75524
75524 23275
23275 98340
98340 81608
81608 91480
91480 75108
75108 56605
56605 93317
93317 41617
41617 77160
77160 727
727 7559...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #13:

score: 0
Runtime Error

input:

1 200000 500000
189127 137023
189127 199761
199761 160701
160701 130639
130639 190908
190908 176819
176819 193363
193363 188021
188021 182446
182446 186028
186028 198828
198828 190792
190792 155378
155378 189428
189428 177276
177276 146159
146159 175923
175923 188073
188073 182206
182206 131072
1310...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #15:

score: 0
Runtime Error

input:

20 200000 1000000
13 10
13 5
19 5
19 20
15 10
15 6
12 6
12 3
8 10
8 2
1 20
1 11
14 10
14 16
18 3
18 7
4 3
9 10
9 17
194055 154514
194055 148156
148156 115271
115271 198116
198116 179433
179433 171975
171975 196600
196600 167194
167194 185078
185078 191409
191409 163496
163496 178243
178243 154093
15...

output:


result: