QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#156756 | #7108. Couleur | ucup-team1477# | AC ✓ | 1520ms | 36096kb | C++17 | 3.6kb | 2023-09-02 14:13:36 | 2023-09-02 14:52:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(y<x)x=y;}
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define mem(x) memset((x),0,sizeof(x))
typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef unsigned u32;
typedef unsigned uint;
typedef unsigned long long u64;
namespace orzjk{
const int SZ=1e6;
char buf[SZ],*p1=buf,*p2=buf;
char nc(){
return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
char fub[SZ],*p3=fub,*p4=fub+SZ;
void pc(char c){
p3==p4&&(fwrite(fub,1,SZ,stdout),p3=fub);
*p3++=c;
}
void flush(){
fwrite(fub,1,p3-fub,stdout),p3=fub;
}
}
using orzjk::nc;
using orzjk::pc;
//#define nc getchar
//#define pc putchar
ll read(){
ll x=0,f=1;char c=nc();
while(c<48)c=='-'&&(f=-1),c=nc();
while(c>47)x=x*10+(c^48),c=nc();
return x*f;
}
template<class T>void write(T x){
static char st[41];
if(!x)return pc(48),void();
char*p=st;
if(x<0)x=-x,pc('-');
for(;x;x/=10)*p++=x%10|48;
do{
pc(*--p);
}while(p!=st);
}
//const int P=1e9+7;
const int P=998244353;
int qp(int a,int k){
int res=1;for(;k;k>>=1,a=1ll*a*a%P)if(k&1)res=1ll*res*a%P;return res;
}
const int maxn=1e5+10;
int n,a[maxn];
#define mid ((l+r)/2)
int tot,rt[maxn];
struct node{
int ls,rs,sum;
}tr[maxn*20];
void ins(int&k,int rt,int l,int r,int x){
tr[k=++tot]=tr[rt],tr[k].sum++;
if(l<r){
if(x<=mid)ins(tr[k].ls,tr[rt].ls,l,mid,x);
else ins(tr[k].rs,tr[rt].rs,mid+1,r,x);
}
}
int ask(int k,int l,int r,int ql,int qr){
if(!k||ql>qr)return 0;
if(ql<=l&&r<=qr)return tr[k].sum;
int res=0;
if(ql<=mid)res=ask(tr[k].ls,l,mid,ql,qr);
if(qr>mid)res+=ask(tr[k].rs,mid+1,r,ql,qr);
return res;
}
#undef mid
int tim,c[maxn],clo[maxn];
void add(int pos){
for(;pos<=n;pos+=pos&-pos){
if(clo[pos]!=tim)clo[pos]=tim,c[pos]=0;
c[pos]++;
}
}
int ask(int pos){
int res=0;
for(;pos;pos&=pos-1)res+=(clo[pos]==tim)*c[pos];
return res;
}
void solve(){
n=read();
rep(i,1,n)a[i]=read();
tot=0;
rep(i,1,n)rt[i]=rt[i-1],ins(rt[i],rt[i-1],1,n,a[i]);
ll all=0;
rep(i,1,n)all+=ask(rt[i-1],1,n,a[i]+1,n);
static ll ans[maxn];
ans[1]=all;
multiset<ll>can;
can.insert(all);
set<int>S;
S.insert(0);
S.insert(n+1);
rep(_,1,n){
// cout<<endl;
// for(ll x:can)cout<<x<<' ';
// cout<<endl;
ll las=*can.rbegin();
write(las),pc("\n "[_<n]);
int x=read()^las;
int l=*--S.lower_bound(x)+1;
int r=*S.lower_bound(x)-1;
S.insert(x);
ll cur=ans[l];
can.erase(can.find(cur));
tim++;
if(x-l<r-x){
ans[l]=0;
per(i,x-1,l)add(a[i]),ans[l]+=ask(a[i]-1);
ans[x+1]=cur-ans[l];
rep(i,l,x)ans[x+1]-=ask(rt[r],1,n,1,a[i]-1)-ask(rt[x-1],1,n,1,a[i]-1);
}else{
ans[x+1]=0;
per(i,r,x+1)add(a[i]),ans[x+1]+=ask(a[i]-1);
ans[l]=cur-ans[x+1];
rep(i,x,r)ans[l]-=ask(rt[x],1,n,a[i]+1,n)-ask(rt[l-1],1,n,a[i]+1,n);
}
if(l<x)can.insert(ans[l]);
if(x<r)can.insert(ans[x+1]);
}
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T;cin>>T;while(T--)solve();
// solve();
orzjk::flush();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7780kb
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: 1520ms
memory: 36096kb
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