QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226042 | #7108. Couleur | fzj2007 | AC ✓ | 1757ms | 35712kb | C++14 | 2.5kb | 2023-10-25 15:00:51 | 2023-10-25 15:00:52 |
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(val.find(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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 1757ms
memory: 35712kb
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