QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#159360 | #7108. Couleur | ucup-team1479# | AC ✓ | 1076ms | 58320kb | C++17 | 3.8kb | 2023-09-02 17:50:01 | 2023-09-02 17:50:02 |
Judging History
answer
#include<bits/stdc++.h>
#define RI int
#define err puts("asd")
#define ll long long
#define ull unsigned long long
#define LL __int128
#define mk make_pair
#define db double
#define FL fflush(stdout)
#define eb emplace_back
#define FR(u,v) for(int i=h[u],v=a[i].t;i;i=a[i].n,v=a[i].t)
#define mem(a,b) memset(a,b,sizeof a)
#define yes puts("Yes")
#define no puts("No")
#define gg puts("-1")
#define vc vector
#define ex exit(0)
#define fi first
#define se second
#define int long long
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
using namespace std;
const int inf=2e9+5;
const ll INF=1e18;
int mod=1e9+7;
inline ll power(ll x,int y){
ll t=1;
while(y){
if(y&1) t=t*x%mod;
x=x*x%mod;y>>=1;
}
return t;
}
inline void gt(int &x,int &y){if(x>y) swap(x,y);}
inline void cmax(int &x,int y){x<y?x=y:0;}
inline void cmin(int &x,int y){x>y?x=y:0;}
inline void AD(int &x,int y){x+=y-mod;x+=x>>31&mod;}
inline ll read(){
ll s=0;char c=getchar();bool f=0;
while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+c-48,c=getchar();
return f?-s:s;
}
const int N=2e5+5;
const int T=32*N;
int n,lc[T],rc[T],f[T],rt[N],L[N],R[N],tot,cnt,a[N],Ti[N];
ll ans,val[N];
multiset<ll>S;
inline void insert(int &x,int pre,int l,int r,int pos){
x=++tot;f[x]=f[pre]+1;
if(l==r) return;
RI mid=l+r>>1;
if(pos<=mid) rc[x]=rc[pre],insert(lc[x],lc[pre],l,mid,pos);
else lc[x]=lc[pre],insert(rc[x],rc[pre],mid+1,r,pos);
}
inline ll ask(int x,int y,int pos){
RI l=0,r=n+1,mid;ll ans=0;
while(l!=r){
mid=l+r>>1;
if(pos<=mid) x=lc[x],y=lc[y],r=mid;
else ans+=f[lc[x]]-f[lc[y]],x=rc[x],y=rc[y],l=mid+1;
}
return ans+f[x]-f[y];
}
inline ll ask1(int x,int y,int pos){
RI l=0,r=n+1,mid;ll ans=0;
while(l!=r){
mid=l+r>>1;
if(pos<=mid) ans+=f[rc[x]]-f[rc[y]],x=lc[x],y=lc[y],r=mid;
else x=rc[x],y=rc[y],l=mid+1;
}
return ans+f[x]-f[y];
}
inline void solve(){
//mem(f,0);mem(lc,0);mem(rc,0);mem(rt,0);
for(RI i=1;i<=tot;++i) f[i]=lc[i]=rc[i]=0;
RI x,y,z,u,v;ll s,p;
n=read();tot=0;
for(RI i=1;i<=n;++i) rt[i]=0,a[i]=read(),insert(rt[i],rt[i-1],0,n+1,a[i]);
val[cnt=1]=0;L[1]=1;R[1]=n;
for(RI i=1;i<=n;++i){
Ti[i]=1;val[1]+=ask(rt[n],rt[i],a[i]-1);
}
S.clear();
S.insert(val[1]);ll las;
for(RI i=1;i<=n;++i){
printf("%lld ",las=(S.size()?(*S.rbegin()):0));
x=read()^las;
if(i==n) break;
y=Ti[x];u=L[y];v=R[y];val[++cnt]=0;
S.erase(S.lower_bound(val[y]));
if(x-u<v-x){
//err;
if(u==x){
val[y]-=ask(rt[v],rt[x],a[x]-1);
S.insert(val[y]);L[y]=x+1;
continue;
}
L[cnt]=u;R[cnt]=x-1;s=0;
for(RI j=u;j<x;++j){
Ti[j]=cnt;
s+=ask(rt[x-1],rt[j],a[j]-1);
val[y]-=ask(rt[v],rt[x],a[j]-1);
}
S.insert(val[cnt]=s);
val[y]-=s+ask(rt[v],rt[x],a[x]-1)+ask1(rt[x-1],rt[u-1],a[x]+1);
S.insert(val[y]);
L[y]=x+1;
}
else{
/*if(u==x){
val[y]-=ask(rt[v],rt[x],a[x]-1);
S.insert(val[y]);L[y]=x+1;
continue;
}
L[cnt]=u;R[cnt]=x-1;s=0;
for(RI j=u;j<x;++j){
Ti[j]=cnt;
s+=ask(rt[x-1],rt[j],a[j]-1);
val[y]-=ask(rt[v],rt[x],a[j]-1);
}
S.insert(val[cnt]=s);
val[y]-=s+ask(rt[v],rt[x],a[x]-1)+ask1(rt[x-1],rt[u-1],a[x]+1);
if(val[y]) S.insert(val[y]);
L[y]=x+1;*/
if(v==x){
val[y]-=ask1(rt[x-1],rt[u-1],a[x]+1);
S.insert(val[y]);R[y]=x-1;
continue;
}
L[cnt]=x+1;R[cnt]=v;s=0;
for(RI j=x+1;j<=v;++j){
Ti[j]=cnt;
s+=ask(rt[v],rt[j],a[j]-1);
val[y]-=ask1(rt[x-1],rt[u-1],a[j]+1);
}
S.insert(val[cnt]=s);
val[y]-=s+ask(rt[v],rt[x],a[x]-1)+ask1(rt[x-1],rt[u-1],a[x]+1);
S.insert(val[y]);
R[y]=x-1;
}
}
putchar(10);
}
signed main(){
RI x,y,z,u,v;
//freopen("1.in","r",stdin);
RI T=read();
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10044kb
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: 1076ms
memory: 58320kb
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