QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176146 | #7108. Couleur | pengpeng_fudan | WA | 0ms | 7764kb | C++14 | 3.3kb | 2023-09-11 11:20:36 | 2023-09-11 11:20:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
int n;
int a[100010];
int p[100010];
#define ls(x) tr[x].l
#define rs(x) tr[x].r
#define sum(x) tr[x].sum
const int N=100010;
struct seg{
int n;
struct node{
int l,r,sum;
}tr[N*40];
int tot;
int rt[N];
void clear(int x){ls(x)=rs(x)=sum(x)=0;}
void clear(){clear(0),tot=0;rt[0]=0;}
seg(int n=0):tot(0){clear(0);rt[0]=0;}
void resize(int x){n=x;}
void pushup(int x){sum(x)=sum(ls(x))+sum(rs(x));}
void upd(int p,int q,int l,int r,int place,int num){
if(l==r) {tr[p].sum=tr[q].sum+num;return ;}
int mid=(l+r)>>1;
if(place<=mid){
rs(p)=rs(q);
ls(p)=++tot;
clear(tot);
upd(ls(p),ls(q),l,mid,place,num);
}
else{
ls(p)=ls(q);
rs(p)=++tot;
clear(tot);
upd(rs(p),rs(q),mid+1,r,place,num);
}
pushup(p);
}
void add(int x,int place,int num){
rt[x]=++tot;
upd(rt[x],rt[x-1],1,n,place,num);
}
int ope_mn(int p,int q,int l,int r,int place){
int mid=(l+r)>>1;
if(l==r) return 0;
if(mid<place) return sum(ls(q))-sum(ls(p))+ope_mn(rs(p),rs(q),mid+1,r,place);
else return ope_mn(ls(p),ls(q),l,mid,place);
}
int query_mn(int l,int r,int num){ if(r<l) return 0;return ope_mn(rt[l-1],rt[r],1,n,num);}
int ope_mx(int p,int q,int l,int r,int place){
int mid=(l+r)>>1;
if(l==r) return 0;
if(mid<place) return ope_mx(rs(p),rs(q),mid+1,r,place);
else return ope_mx(ls(p),ls(q),l,mid,place)+sum(rs(q))-sum(rs(p));
}
int query_mx(int l,int r,int num){ if(r<l) return 0;return ope_mx(rt[l-1],rt[r],1,n,num);}
};
seg sg;
struct node{
int l,r;
int ni;
bool operator<(node a){return ni>a.ni;}
};
node ve[100010];
multiset<int> qe;
int fa[100010];
int cnt=0;
void solve() {
cin>>n;
sg.clear();
qe.clear();
sg.resize(n);
cnt=1;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>p[i];
int ni_num=0;
for(int i=1;i<=n;i++){
ni_num+=sg.query_mx(1,i-1,a[i]);
fa[i]=1;
sg.add(i,a[i],1);
}
ve[1]={1,n,ni_num};
qe.insert(-ni_num);
for(int i=1;i<=n;i++){
int t=-(*qe.begin());
if(t>n) return ;
cout<<t<<' ';
int ope=t^p[i];
int l=ve[fa[ope]].l,r=ve[fa[ope]].r;
qe.erase(qe.find(-ve[fa[ope]].ni));
int ni_num=0;
if(ope-l<r-ope){
for(int j=l;j<ope;j++) ni_num+=sg.query_mn(j+1,ope-1,a[j]);
if(ope!=l) ve[++cnt]={l,ope-1,ni_num};
qe.insert(-ni_num);
int lz=fa[ope];
int qz=ve[fa[ope]].ni-ni_num-sg.query_mx(l,ope-1,a[ope]);
for(int j=l;j<=ope;j++){
fa[j]=cnt;
qz-=sg.query_mn(ope+1,r,a[j]);
}
ve[lz].ni=qz;
ve[lz].l=ope+1;
qe.insert(-qz);
}
else{
for(int j=ope+1;j<=r;j++) ni_num+=sg.query_mn(j+1,r,a[j]);
if(ope!=r) ve[++cnt]={ope+1,r,ni_num};
qe.insert(-ni_num);
int lz=fa[ope];
int qz=ve[fa[ope]].ni-ni_num-sg.query_mn(ope+1,r,a[ope]);
for(int i=ope;i<=r;i++){
fa[i]=cnt;
qz-=sg.query_mx(l,ope-1,a[i]);
}
ve[lz].ni=qz;
ve[lz].r=ope-1;
qe.insert(-qz);
}
}
cout<<'\n';
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
int _ = 1;
cin >> _;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7764kb
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:
result:
wrong answer 1st lines differ - expected: '7 0 0 0 0', found: ''