QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#160616 | #7108. Couleur | ucup-team1732# | AC ✓ | 2954ms | 33560kb | C++14 | 2.9kb | 2023-09-02 20:58:45 | 2023-09-02 20:58:46 |
Judging History
answer
// created: Sep/02/2023 20:39:26
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
template<typename T>void readmain(T &x)
{
bool neg=false;
unsigned int c=getchar();
for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
constexpr int N=1e5+5;
namespace seg
{
constexpr int M=3e6;
struct node
{
int ls,rs,sum;
}s[M];
int sta[M],top;
void init(){for(int i=M;--i;)sta[top++]=i;}
int newnode(){return --top,s[sta[top]]=s[0],sta[top];}
void delnode(int x){sta[top++]=x;}
int update(int p,int l,int r,int x,int v)
{
if(!p)p=newnode();
if(r-l==1)
{
s[p].sum+=v;
if(!s[p].sum)delnode(p),p=0;
return p;
}
int mid=(l+r)>>1;
if(x<mid)s[p].ls=update(s[p].ls,l,mid,x,v);
else s[p].rs=update(s[p].rs,mid,r,x,v);
s[p].sum=s[s[p].ls].sum+s[s[p].rs].sum;
if(!s[p].sum)delnode(p),p=0;
return p;
}
int query(int p,int l,int r,int x,int y)
{
if(!p)return 0;
if(x==l&&r==y)return s[p].sum;
int mid=(l+r)>>1;
if(y<=mid)return query(s[p].ls,l,mid,x,y);
if(mid<=x)return query(s[p].rs,mid,r,x,y);
return query(s[p].ls,l,mid,x,mid)+query(s[p].rs,mid,r,mid,y);
}
}
struct interval
{
int l,r,rt;
long long ans;
friend bool operator<(interval x,interval y){return x.l<y.l;}
};
int tt,n,a[N],id[N];
set<interval> s;
priority_queue<long long> add,del;
long long query()
{
while(!del.empty()&&add.top()==del.top())add.pop(),del.pop();
return add.top();
}
void create(int l,int r)
{
if(l==r)return;
int rt=0;long long ans=0;
F(i,l,r)ans+=seg::query(rt,0,n,a[i],n),rt=seg::update(rt,0,n,a[i],1);
add.emplace(ans);
s.insert({l,r,rt,ans});
}
int main()
{
seg::init();
read(tt);
while(tt--)
{
read(n);
F(i,0,n)read(a[i]),id[i]=i;
sort(id,id+n,[](int u,int v){return a[u]!=a[v]?a[u]<a[v]:u<v;});
F(i,0,n)a[id[i]]=i;
create(0,n);
F(_,0,n)
{
long long lans=query(),enc;read(enc);
printf("%lld ",lans);
int u=(int)(enc^lans)-1;
auto it=prev(s.upper_bound({u,0,0,0}));
int l=it->l,r=it->r,rt=it->rt;long long ans=it->ans;
s.erase(it);del.emplace(ans);
if(2*u>l+r)
{
for(int i=r;--i>=u;)
{
rt=seg::update(rt,0,n,a[i],-1);
ans-=seg::query(rt,0,n,a[i],n);
}
if(l<u)
{
add.emplace(ans);
s.insert({l,u,rt,ans});
}
create(u+1,r);
}
else
{
F(i,l,u+1)
{
rt=seg::update(rt,0,n,a[i],-1);
ans-=seg::query(rt,0,n,0,a[i]+1);
}
if(u+1<r)
{
add.emplace(ans);
s.insert({u+1,r,rt,ans});
}
create(l,u);
}
}
while(!add.empty())add.pop();
while(!del.empty())del.pop();
puts("");
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 16632kb
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: 2954ms
memory: 33560kb
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 ...
result:
ok 11116 lines
Extra Test:
score: 0
Extra Test Passed