QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#157467 | #7108. Couleur | ucup-team206# | AC ✓ | 1351ms | 28992kb | C++17 | 2.0kb | 2023-09-02 15:23:26 | 2023-09-02 15:23:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1e3+7;
int T,n,a[N],rt[N];
long long f[N];
long long ans=0;
int cnt;
struct T{
int ls,rs,sum;
}t[N*31];
void ins(int x,int &y,int l,int r,int p)
{
y=++cnt;
t[y]=t[x];
t[y].sum++;
if(l==r)
return;
int mid=(l+r)>>1;
if(p<=mid)
ins(t[x].ls,t[y].ls,l,mid,p);
else
ins(t[x].rs,t[y].rs,mid+1,r,p);
}
int qry(int x,int y,int l,int r,int L,int R)
{
if(L>R)
return 0;
if(L<=l&&r<=R)
return t[y].sum-t[x].sum;
int mid=(l+r)>>1;
int ret=0;
if(L<=mid)
ret+=qry(t[x].ls,t[y].ls,l,mid,L,R);
if(R>mid)
ret+=qry(t[x].rs,t[y].rs,mid+1,r,L,R);
return ret;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
cnt=0;
long long ans=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
ins(rt[i-1],rt[i],1,n,a[i]);
ans+=qry(rt[0],rt[i-1],1,n,a[i]+1,n);
}
map<long long,int> cnt;
set<pair<int,int> >s;
f[1]=ans;
cnt[ans]++;
s.insert({1,n});
for(int i=1;i<=n;i++)
{
while(!cnt[ans])
{
cnt.erase(prev(cnt.end()));
ans=prev(cnt.end())->first;
}
long long p;
scanf("%lld",&p);
p^=ans;
printf("%lld%c",ans," \n"[i==n]);
auto it=prev(s.upper_bound({p,n+1}));
auto [l,r]=*it;
s.erase(it);
assert(l<=p&&p<=r);
cnt[f[l]]--;
long long tot=f[l];
if(l<p)
{
s.insert({l,p-1});
if(p-l<=r-p)
{
f[l]=0;
for(int i=l;i<p;i++)
f[l]+=qry(rt[l-1],rt[i],1,n,a[i]+1,n);
}
else
{
f[l]=tot;
for(int i=p;i<=r;i++)
f[l]-=qry(rt[l-1],rt[i],1,n,a[i]+1,n);
}
cnt[f[l]]++;
}
if(p<r)
{
s.insert({p+1,r});
if(r-p<=p-l)
{
f[p+1]=0;
for(int i=p+1;i<=r;i++)
f[p+1]+=qry(rt[p],rt[i],1,n,a[i]+1,n);
}
else
{
f[p+1]=tot;
for(int i=p;i>=l;i--)
f[p+1]-=qry(rt[i],rt[r],1,n,1,a[i]-1);
}
cnt[f[p+1]]++;
}
}
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5844kb
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: 1351ms
memory: 28992kb
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