QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171229 | #7108. Couleur | kjhhjki# | AC ✓ | 1379ms | 56148kb | C++14 | 2.5kb | 2023-09-09 16:39:01 | 2023-09-09 16:39:01 |
Judging History
answer
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int MAXN=100003;
typedef long long LL;
struct node {
int tot;
node *ch[2];
node() {
tot=0;
ch[0]=ch[1]=NULL;
}
};
node data[MAXN*20];
node *root[MAXN];
node *ncnt=&data[0];
LL read() {
LL x=0;char s=getchar();
while(s<'0'||s>'9') s=getchar();
while(s>='0'&&s<='9') x=x*10+s-'0', s=getchar();
return x;
}
void Build(node *&rt,int l,int r) {
rt=ncnt++;
rt->tot=0;
if(l==r) {
rt->ch[0]=rt->ch[1]=NULL;
return ;
}
int mid=(l+r)>>1;
Build(rt->ch[0],l,mid);
Build(rt->ch[1],mid+1,r);
}
void Insert(node *&x,node *y,int val,int l,int r) {
x=ncnt++;
*x=*y; x->tot++;
if(l==r) return ;
int mid=(l+r)>>1;
if(val<=mid) Insert(x->ch[0],y->ch[0],val,l,mid);
else Insert(x->ch[1],y->ch[1],val,mid+1,r);
}
int Query(node *x,node *y,int k,int l,int r) { //how many <= k
if(l==r) return y->tot - x->tot;
int mid=(l+r)>>1;
if(k<=mid) return Query(x->ch[0],y->ch[0],k,l,mid);
return Query(x->ch[1],y->ch[1],k,mid+1,r) + y->ch[0]->tot - x->ch[0]->tot;
}
int n, a[MAXN], rhs[MAXN];
LL val[MAXN], z[MAXN];
set<int>seq;
multiset<LL,greater<LL> >ans;
void Solve() {
seq.clear(), ans.clear();
ncnt=&data[0];
Build(root[0],0,n=read());
for(int i=1;i<=n;i++)
Insert(root[i],root[i-1],a[i]=read(),0,n);
rhs[1]=n, val[1]=0;
for(int i=2;i<=n;i++)
val[1]+=i-1-Query(root[0],root[i-1],a[i],0,n);
seq.insert(1), ans.insert(val[1]);
for(int i=1,p;i<=n;i++) {
z[i]=*ans.begin(), p=read()^z[i];
set<int>::iterator it=seq.upper_bound(p);
int pos=*(--it);
seq.erase(pos), ans.erase(ans.find(val[pos]));
LL lval, rval;
if(p-pos<=rhs[pos]-p) {
lval=0, rval=val[pos];
for(int i=pos;i<p;i++) {
rval-=Query(root[i],root[rhs[pos]],a[i]-1,0,n);
lval+=Query(root[i],root[p-1],a[i]-1,0,n);
}
rval-=Query(root[p],root[rhs[pos]],a[p]-1,0,n);
} else {
lval=val[pos], rval=0;
for(int i=rhs[pos];i>p;i--) {
lval-=(i-pos)-Query(root[pos-1],root[i-1],a[i],0,n);
rval+=(i-1-p)-Query(root[p],root[i-1],a[i],0,n);
}
lval-=(p-pos)-Query(root[pos-1],root[p-1],a[p],0,n);
}
if(p!=rhs[pos])
rhs[p+1]=rhs[pos], seq.insert(p+1), ans.insert(val[p+1]=rval);
if(p!=pos)
rhs[pos]=p-1, seq.insert(pos), ans.insert(val[pos]=lval);
}
for(int i=1;i<n;i++)
printf("%lld ",z[i]);
printf("%lld\n",z[n]);
}
int main() {
int T;
scanf("%d",&T);
for(int Cas=1;Cas<=T;Cas++)
Solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 53388kb
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: 1379ms
memory: 56148kb
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