QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226034 | #7108. Couleur | fzj2007 | WA | 0ms | 3616kb | C++14 | 2.5kb | 2023-10-25 14:53:34 | 2023-10-25 14:53:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
x=0;
char ch=getchar();
bool flag=0;
while(ch>'9'||ch<'0') flag=flag||ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
read(x),read(args...);
}
template<typename T>inline void prt(T x){
if(x>9) prt(x/10);
putchar(x%10+'0');
}
template<typename T>inline void put(T x){
if(x<0) putchar('-'),x=-x;
prt(x);
}
template<typename T>inline void put(char ch,T x){
put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
put(ch,x),put(ch,args...);
}
#define N 100005
#define ll long long
int n,w[N],rt[N],idx;
struct node{
int ls,rs,siz;
}t[N<<5];
#define lc(x) t[x].ls
#define rc(x) t[x].rs
inline void update(int &x,int y,int l,int r,int pos){
t[x=++idx]=t[y],t[x].siz++;
if(l==r) return;
int mid=l+r>>1;
if(pos<=mid) update(lc(x),lc(y),l,mid,pos);
else update(rc(x),rc(y),mid+1,r,pos);
}
inline int query(int x,int y,int l,int r,int ql,int qr){
if(!x||ql>qr||l>qr||r<ql) return 0;
if(ql<=l&&qr>=r) return t[x].siz-t[y].siz;
int mid=l+r>>1,res=0;
if(ql<=mid) res+=query(lc(x),lc(y),l,mid,ql,qr);
if(qr>mid) res+=query(rc(x),rc(y),mid+1,r,ql,qr);
return res;
}
ll dis[N];
inline void solve(){
read(n);
for(int i=1;i<=n;i++) read(w[i]),update(rt[i],rt[i-1],1,n,w[i]);
for(int i=1;i<=n;i++) dis[0]+=query(rt[i-1],0,1,n,w[i]+1,n);
multiset<ll> val;
multiset<int> pos;
val.insert(dis[0]);
pos.insert(0),pos.insert(n+1);
for(int c=1;c<=n;c++){
ll now,z,tmp;
read(z),put(c==n?'\n':' ',now=*(--val.end())),z^=now;
auto it=pos.lower_bound(z);
int r=(*it),l=*(--it);
tmp=dis[l],val.erase(dis[l]),dis[l]=0;
tmp-=query(rt[z-1],rt[l],1,n,w[z]+1,n);
tmp-=query(rt[r-1],rt[z],1,n,1,w[z]-1);
if(z-l<=r-z){
for(int i=l+1;i<z;i++){
tmp-=query(rt[r-1],rt[z],1,n,1,w[i]-1);
dis[l]+=query(rt[i-1],rt[l],1,n,w[i]+1,n);
}
dis[z]=tmp-dis[l];
}else{
for(int i=z+1;i<r;i++){
tmp-=query(rt[z-1],rt[l],1,n,w[i]+1,n);
dis[z]+=query(rt[i-1],rt[z],1,n,w[i]+1,n);
}
dis[l]=tmp-dis[z];
}
val.insert(dis[l]),val.insert(dis[z]);
pos.insert(z);
}
for(int i=1;i<=n;i++) rt[i]=0;
for(int i=0;i<=n+1;i++) dis[i]=0;
for(int i=1;i<=idx;i++) t[i].ls=t[i].rs=t[i].siz=0;
idx=0;
}
int T;
int main(){
read(T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
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 0 0 1 1 1 0 0 0
result:
wrong answer 3rd lines differ - expected: '42 31 21 14 14 4 1 1 1 0 0 0 0 0 0', found: '42 31 21 14 14 4 1 0 0 1 1 1 0 0 0'