QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153220 | #7108. Couleur | PhantomThreshold# | AC ✓ | 1568ms | 32208kb | C++20 | 3.1kb | 2023-08-29 17:56:46 | 2023-08-29 17:56:47 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
//#define int long long
using namespace std;
const int maxn = 105000;
const int maxp = maxn*30;
struct segment
{
int tot;
int t[maxp],tn;
int seg[maxp],lc[maxp],rc[maxp];
void init()
{
tot=0; tn=0;
}
void delp(int &x)
{
t[++tn]=x;
x=0;
}
int newnode()
{
int x;
if(tn) x=t[tn--];
else x=++tot;
seg[x]=lc[x]=rc[x]=0;
return x;
}
int loc;
ll insr(int &x,const int l,const int r)
{
if(!x) x=newnode();
seg[x]++;
if(l==r) return 0;
int mid=(l+r)>>1;
if(loc<=mid) return seg[rc[x]]+insr(lc[x],l,mid);
else return insr(rc[x],mid+1,r);
}
ll dell(int &x,const int l,const int r)
{
seg[x]--;
if(l==r)
{
if(!seg[x]) delp(x);
return 0;
}
int mid=(l+r)>>1;
ll ret=0;
if(loc<=mid) ret= dell(lc[x],l,mid);
else ret= seg[lc[x]]+ dell(rc[x],mid+1,r);
if(!seg[x]) delp(x);
return ret;
}
ll delr(int &x,const int l,const int r)
{
seg[x]--;
if(l==r)
{
if(!seg[x]) delp(x);
return 0;
}
int mid=(l+r)>>1;
ll ret=0;
if(loc<=mid) ret= seg[rc[x]]+delr(lc[x],l,mid);
else ret=delr(rc[x],mid+1,r);
if(!seg[x]) delp(x);
return ret;
}
}seg;
// r l rt num
set< tuple<int,int,int,ll> >rtS;
// num r
set< pair<ll,int> >numS;
int a[maxn],n;
void build(const int l,const int r)
{
int rt=0;
ll num=0;
for(int i=l;i<=r;i++)
{
seg.loc=a[i];
num+= seg.insr(rt,1,n);
}
rtS.emplace( r,l,rt,num );
numS.emplace( num,r );
}
void solve(const int pos)
{
auto it= rtS.lower_bound( make_tuple( pos,0,0,0ll ) );
auto [r,l,rt,num]= *it;
rtS.erase(it);
numS.erase( make_pair(num,r) );
int mid=(l+r)>>1;
if(pos<=mid)
{
for(int i=l;i<=pos;i++)
{
seg.loc=a[i];
num-=seg.dell(rt,1,n);
}
if(pos+1<=r)
{
rtS.emplace(r,pos+1,rt,num);
numS.emplace( num,r );
}
if(l<=pos-1) build(l,pos-1);
}
else
{
for(int i=r;i>=pos;i--)
{
seg.loc=a[i];
num-=seg.delr(rt,1,n);
}
if(l<=pos-1)
{
rtS.emplace(pos-1,l,rt,num);
numS.emplace( num,pos-1 );
}
if(pos+1<=r) build(pos+1,r);
}
}
int main()
{
//freopen("tmp.in","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
mt19937 rng(58);
int Tcase=10; cin>>Tcase;
int sumn=0;
while(Tcase--)
{
cin>>n;
sumn+=n;
assert(sumn<=1000000);
// n=100000;
for(int i=1;i<=n;i++) /*a[i]=rng()%n+1;*/cin>>a[i];
rtS.clear();
numS.clear();
seg.init();
build(1,n);
ll lastans;
// vector<int> perm(n+5);
// for(int i=1;i<=n;i++)perm[i]=i;
// random_shuffle(perm.begin()+1,perm.begin()+n+1,[&](int x){return rng()%x;});
vector<int> vis(n+5);
for(int i=1;i<=n;i++)
{
// cerr<<i<<" : ";
// for(auto it:numS) cerr<< it.first <<' '<< it.second <<' ';
// cerr<<endl;
auto it=numS.end();
it--;
lastans=it->first;
cout<< lastans << " \n"[i==n];
ll p; cin>>p; p^=lastans;
assert((1<=p and p<=n and not vis[p]));
solve(p);
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11988kb
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: 1568ms
memory: 32208kb
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