QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190927 | #7108. Couleur | Geospiza# | AC ✓ | 1721ms | 51404kb | C++20 | 4.3kb | 2023-09-29 15:56:45 | 2023-09-29 15:56:46 |
Judging History
answer
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
//#define int ll
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
const int N=1e5+5;
int t,n,m,k,tt;
int ls[N<<5],rs[N<<5],root[N<<5];
ll tr[N<<5];
void update(int l,int r,int pos,ll x,int &rt,int pre)
{
rt=++tt;
ls[rt]=ls[pre];
rs[rt]=rs[pre];
tr[rt]=tr[pre];
if(l==r)
{
tr[rt]+=x;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid)update(l,mid,pos,x,ls[rt],ls[pre]);
else update(mid+1,r,pos,x,rs[rt],rs[pre]);
tr[rt]=tr[ls[rt]]+tr[rs[rt]];
}
ll query(int l,int r,int ql,int qr,int rt,int pre)
{
if(l>qr||r<ql)return 0;
if(l>=ql&&r<=qr)return tr[pre]-tr[rt];
int mid=(l+r)>>1;
ll res=0;
res+=query(l,mid,ql,qr,ls[rt],ls[pre]);
res+=query(mid+1,r,ql,qr,rs[rt],rs[pre]);
return res;
}
struct node
{
int l,r;
ll w;
bool operator < (const node &a)const{
if(w!=a.w)return w>a.w;
if(l!=a.l)return l>a.l;
return r>a.r;
}
}tree[N<<2],lazy[N<<2];
set<node>s;
void pushdown(int p)
{
if(lazy[p].l!=-1)
{
tree[p<<1]=lazy[p];
tree[p<<1|1]=lazy[p];
lazy[p<<1]=lazy[p];
lazy[p<<1|1]=lazy[p];
lazy[p].l=-1;
}
return ;
}
void update(int p,int l,int r,int ql,int qr,node &c)
{
if(l>qr||r<ql)return ;
if(l>=ql&&r<=qr)
{
tree[p]=c;
lazy[p]=c;
return ;
}
pushdown(p);
int mid=(l+r)>>1;
update(p<<1,l,mid,ql,qr,c);
update(p<<1|1,mid+1,r,ql,qr,c);
}
node query(int p,int l,int r,int x)
{
if(l==r)return tree[p];
pushdown(p);
int mid=(l+r)>>1;
if(x<=mid)return query(p<<1,l,mid,x);
else return query(p<<1|1,mid+1,r,x);
}
ll a[N];
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int T=1;
cin>>T;
while(T--)
{
tt=0;
cin>>n;
node bg={1,n,0LL};
rep(i,1,n)
{
cin>>a[i];
bg.w+=query(1,n,a[i]+1,n,root[0],root[i-1]);
update(1,n,a[i],1,root[i],root[i-1]);
}
s.insert(bg);
update(1,1,n,1,n,bg);
ll ans=0;
rep(i,1,n)
{
ll x;
cin>>x;
ans=(s.begin()->w);
x^=ans;
cout<<ans<<" \n"[i==n];
if(!ans)continue;
node res=query(1,1,n,x);
s.erase(res);
int L=x-res.l;
int R=res.r-x;
if(L>R)
{
L=res.l,R=res.r;
node k1={x+1,R,0};
node k2={L,x-1,res.w};
rep(j,k1.l,k1.r)
{
k1.w+=query(1,n,a[j]+1,n,root[k1.l-1],root[j-1]);
k2.w-=query(1,n,a[j]+1,n,root[k2.l-1],root[k2.r]);
}
k2.w-=k1.w;
k2.w-=query(1,n,a[x]+1,n,root[k2.l-1],root[k2.r]);
k2.w-=query(1,n,1,a[x]-1,root[k1.l-1],root[k1.r]);
if(k1.r>=k1.l)
{
s.insert(k1);
update(1,1,n,k1.l,k1.r,k1);
}
if(k2.r>=k2.l)
{
s.insert(k2);
update(1,1,n,k2.l,k2.r,k2);
}
}
else
{
L=res.l,R=res.r;
node k1={x+1,R,res.w};
node k2={L,x-1,0};
rep(j,k2.l,k2.r)
{
k2.w+=query(1,n,a[j]+1,n,root[k2.l-1],root[j-1]);
k1.w-=query(1,n,1,a[j]-1,root[k1.l-1],root[k1.r]);
}
k1.w-=k2.w;
k1.w-=query(1,n,1,a[x]-1,root[k1.l-1],root[k1.r]);
k1.w-=query(1,n,a[x]+1,n,root[k2.l-1],root[k2.r]);
if(k1.r>=k1.l)
{
s.insert(k1);
update(1,1,n,k1.l,k1.r,k1);
}
if(k2.r>=k2.l)
{
s.insert(k2);
update(1,1,n,k2.l,k2.r,k2);
}
}
}
}
}
/*
1
5
4 3 1 1 1
5 4 5 3 1
3
5
43111
54531
10
9714785748
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
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5760kb
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: 1721ms
memory: 51404kb
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