QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235096#7108. CouleurHayasaAC ✓3726ms52092kbC++142.1kb2023-11-02 13:50:132023-11-02 13:50:14

Judging History

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

  • [2023-11-02 13:50:14]
  • 评测
  • 测评结果:AC
  • 用时:3726ms
  • 内存:52092kb
  • [2023-11-02 13:50:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long ;
const int M=2e5+10;
int ls[M*30],rs[M*30],s[M*30],tot,n;
void ins(int &cur,int pre,int v,int L=0,int R=n+1){
	cur=++tot;
	ls[cur]=ls[pre];
	rs[cur]=rs[pre];
	s[cur]=s[pre]+1;
	if(L==R)return ;
	int mid=(L+R)>>1;
	if(v<=mid)ins(ls[cur],ls[pre],v,L,mid);
	else ins(rs[cur],rs[pre],v,mid+1,R);
}
int qry(int cur,int l,int r,int L=0,int R=n+1){
	if(!cur)return 0;
	if(L==l&&r==R)return s[cur];
	int mid=(L+R)>>1;
	if(r<=mid)return qry(ls[cur],l,r,L,mid);
	else if(l>mid)return qry(rs[cur],l,r,mid+1,R);
	return qry(ls[cur],l,mid,L,mid)+
		qry(rs[cur],mid+1,r,mid+1,R);
}
int A[M],rt[2][M];
ll res[M];
multiset<ll>ans;
set<int>st;
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&A[i]);
	for(int i=1;i<=n;++i)
		ins(rt[0][i],rt[0][i-1],A[i]);
	for(int i=n;i;--i)
		ins(rt[1][i],rt[1][i+1],A[i]);
	for(int i=1;i<=n;++i)
		res[1]+=qry(rt[0][i-1],A[i]+1,n+1);
	ans.insert(res[1]);
	st.insert(0);
	st.insert(n+1);
	ll lst=0;
	for(int q=1;q<=n;++q){
		printf("%lld ",lst=*(--ans.end()));
		ll x;
		scanf("%lld",&x);
		x^=lst;
	 	int r=*st.upper_bound(x)-1;
		int l=*(--st.upper_bound(x))+1;
		st.insert((int)x);
		
		ll ans1=res[l];
		ans1-=qry(rt[0][x-1],A[x]+1,n+1)-qry(rt[0][l-1],A[x]+1,n+1);
		ans1-=qry(rt[1][x+1],0,A[x]-1)-qry(rt[1][r+1],0,A[x]-1);
		ll ans2=0,ans3=0;
		if(x-l<r-x){
			for(int i=l;i<x;++i){
				ans2+=qry(rt[0][i-1],A[i]+1,n+1)-qry(rt[0][l-1],A[i]+1,n+1);
				ans1-=qry(rt[1][x+1],0,A[i]-1)-qry(rt[1][r+1],0,A[i]-1);
			}
			ans3=ans1-ans2;
		}else{
			for(int i=r;i>x;--i){
				ans3+=qry(rt[0][i-1],A[i]+1,n+1)-qry(rt[0][x],A[i]+1,n+1);
				ans1-=qry(rt[0][x-1],A[i]+1,n+1)-qry(rt[0][l-1],A[i]+1,n+1);
			}
			ans2=ans1-ans3;
		}
		ans.erase(ans.find(res[l]));
		if(l!=x){
			res[l]=ans2;
			ans.insert(ans2);
		}else res[x]=0;
		if(r!=x){
			res[x+1]=ans3;
			ans.insert(ans3);
		}else res[x]=0;
	}
	puts("");
	ans.clear();
	st.clear();
	for(int i=1;i<=n;++i)rt[0][i]=rt[1][i]=res[i]=tot=0;
}
int main(){
	//freopen("hayasa","r",stdin);
	int T;
	scanf("%d",&T);
	while(T--)solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3726ms
memory: 52092kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed