QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72993#5425. Proposition CompositionchenshiWA 88ms9976kbC++1.9kb2023-01-21 15:38:582023-01-21 15:38:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-21 15:38:59]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:9976kb
  • [2023-01-21 15:38:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int o=2.5e5+10;
int T,n,m,bl[o],c[o],C[o],cnt,tot,rt[o],s[o],ls[o],rs[o],w[o];
long long ans;set<int> S;mt19937 rnd(time(0));
inline void update(int id){s[id]=s[ls[id]]+s[rs[id]]+1;}
void merge(int&id,int x,int y){
	if(!x||!y){id=x|y;return;}
	if(w[x]<w[y]) id=x,merge(rs[id],rs[x],y);
	else id=y,merge(ls[id],x,ls[y]);
	update(id);
}
void split(int id,int val,int&x,int&y){
	if(!id){x=y=0;return;}
	if(id<=val) x=id,split(rs[id],val,rs[x],y);
	else y=id,split(ls[id],val,x,ls[y]);
	update(id);
}
void dfs(int id,int val){if(id) bl[id]=val,dfs(ls[id],val),dfs(rs[id],val);}
inline void calc(int x,int coef){
	if(!C[x]){cnt+=coef*s[rt[x]];return;}
	if(C[x]==1) ans+=coef*s[rt[x]]*(s[rt[x]]+1ll)/2;
	else ans+=coef*s[rt[x]]*(s[rt[x]]-1ll)/2;
}
int main(){
	for(scanf("%d",&T);T--;S.clear(),ans=0){
		scanf("%d%d",&n,&m);cnt=n-1;tot=1;
		for(int i=1;i<n;++i)
			S.insert(i),c[i]=0,bl[i]=1,w[i]=rnd(),s[i]=1,ls[i]=rs[i]=0,merge(rt[1],rt[1],i);
		for(int i=1,l,r,x,y;i<=m;printf("%lld\n",ans+cnt*(cnt-1ll)/2+cnt*(n+i-1ll-cnt)),++i){
			scanf("%d%d",&l,&r);
			if(l>r) swap(l,r);
			if(l>1&&bl[l]==bl[l-1]){
				calc(bl[l],-1);
				split(rt[bl[l]],l-1,x,y);split(y,r-1,rt[++tot],y);merge(rt[bl[l]],x,y);
				C[tot]=C[bl[l]];calc(bl[l],1);calc(tot,1);
				if(s[rt[bl[l]]]<s[rt[tot]]) swap(rt[bl[l]],rt[tot]);
				dfs(rt[tot],tot);
			}
			if(r<n&&bl[r]==bl[r-1]){
				calc(bl[r],-1);
				split(rt[bl[r]],r-1,x,y);split(x,l-1,x,rt[++tot]);merge(rt[bl[r]],x,y);
				C[tot]=C[bl[r]];calc(bl[r],1);calc(tot,1);
				if(s[rt[bl[r]]]<s[rt[tot]]) swap(rt[bl[r]],rt[tot]);
				dfs(rt[tot],tot);
			}
			--l;
			for(set<int>::iterator iter;(iter=S.upper_bound(l))!=S.end()&&(*iter)<r;){
				calc(bl[l=*iter],-1);C[bl[l]]=++c[l];calc(bl[l],1);
				if(c[l]==2) S.erase(l);
			}
		}
		for(int i=1;i<=tot;++i) rt[i]=C[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9968kb

input:

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

output:

6
5
6
21
24
10
15
12
3
2

result:

ok 10 numbers

Test #2:

score: -100
Wrong Answer
time: 88ms
memory: 9976kb

input:

45540
10 9
10 1
1 10
10 1
1 10
1 10
10 1
1 10
3 3
10 1
10 4
1 2
1 10
3 4
1 10
7 6
7 1
5 6
1 7
6 6
7 1
6 7
9 7
3 3
7 7
5 4
1 1
9 1
9 1
6 5
8 7
1 8
4 4
5 6
1 1
1 8
6 6
4 5
3 3
3 2
3 1
3 3
3 9
3 1
3 3
2 2
3 3
3 1
2 2
1 1
2 3
3 1
10 1
2 1
7 1
1 7
3 8
1 3
1 3
3 3
1 3
2 2
1 3
1 3
3 3
3 6
3 1
1 3
1 3
1 3
1...

output:

45
36
36
36
36
36
36
36
36
45
36
28
21
21
15
10
10
10
10
36
44
50
57
28
21
15
28
28
21
21
15
15
10
3
1
1
3
3
3
3
1
1
1
0
0
45
21
3
1
1
1
1
1
1
1
3
1
1
1
1
1
45
36
36
36
36
36
36
36
3
3
1
0
0
0
0
0
0
3
1
0
0
15
10
10
0
0
0
0
0
0
0
0
28
34
21
6
6
6
6
1
0
0
21
15
15
0
0
0
0
0
0
0
45
53
0
0
0
0
0
0
0
0
...

result:

wrong answer 19th numbers differ - expected: '6', found: '10'