QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#157679#7108. Couleurucup-team1004#AC ✓2687ms38964kbC++142.3kb2023-09-02 15:41:372023-09-02 15:41:38

Judging History

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

  • [2023-09-02 15:41:38]
  • 评测
  • 测评结果:AC
  • 用时:2687ms
  • 内存:38964kb
  • [2023-09-02 15:41:37]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*25+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,A[N],B[N];
namespace CT{
	int f[M],Ct,L[M],R[M];
	void Cl(){for(int i=1;i<=Ct;i++) f[i]=L[i]=R[i]=0;Ct=0;}
	void CP(int &v){f[++Ct]=f[v];L[Ct]=L[v];R[Ct]=R[v];v=Ct;}
	void add(int x,int &v,int l=1,int r=n){
		CP(v);f[v]++;if(l==r) return;
		int m=l+r>>1;return x<=m?add(x,L[v],l,m):add(x,R[v],m+1,r);
	}
	int qry(int x,int y,int &v,int l=1,int r=n){
		if(x>y||!v) return 0;if(x<=l&&r<=y) return f[v];int m=l+r>>1;
		return (x<=m?qry(x,y,L[v],l,m):0)+(y>m?qry(x,y,R[v],m+1,r):0);
	}
}
int Ro[N];set<int> f;
int qry(int l,int r,int x,int y){return CT::qry(l,r,Ro[y])-CT::qry(l,r,Ro[x-1]);}
multiset<ll> g;ll ans[N],w[N];
void Solve(){
	int i,j;scanf("%d",&n);CT::Cl();
	for(i=1;i<=n;i++) scanf("%d",&A[i]),Ro[i]=Ro[i-1],CT::add(A[i],Ro[i]);
	f.clear();f.insert(0);f.insert(n+1);
	fill(w,w+n+2,0);
	for(i=1;i<=n;i++) w[1]+=qry(A[i]+1,n,1,i-1);g.clear();g.insert(w[1]);
	for(i=1;i<=n;i++){
		ans[i-1]=*g.rbegin();printf("%lld%c",ans[i-1]," \n"[i==n]);
		ll x;scanf("%lld",&x);x^=ans[i-1];
		// cerr<<x<<'\n';
		int pre=*--f.LB(x),suf=*f.LB(x);f.insert(x);
		pre++;suf--;g.erase(g.LB(w[pre]));
		// cerr<<"pre "<<pre<<' '<<suf<<'\n';
		if(x-pre<=suf-x){
			w[x+1]=w[pre];w[pre]=0;
			for(j=pre;j<x;j++) w[pre]+=qry(A[j]+1,n,pre,j-1);
			w[x+1]-=w[pre]+qry(1,A[x]-1,x+1,suf)+qry(A[x]+1,n,pre,x-1);
			for(j=pre;j<x;j++) w[x+1]-=qry(1,A[j]-1,x+1,suf);
		}else{
			for(j=x+1;j<=suf;j++) w[x+1]+=qry(A[j]+1,n,x+1,j-1);
			w[pre]-=w[x+1]+qry(1,A[x]-1,x+1,suf)+qry(A[x]+1,n,pre,x-1);
			for(j=x+1;j<=suf;j++) w[pre]-=qry(A[j]+1,n,pre,x-1);
		}
		g.insert(w[pre]);g.insert(w[x+1]);
		// cerr<<w[pre]<<' '<<w[x+1]<<'\n';
	}
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2687ms
memory: 38964kb

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 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed