QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176025 | #7108. Couleur | pengpeng_fudan | RE | 1ms | 7780kb | C++14 | 3.3kb | 2023-09-11 08:14:17 | 2023-09-11 08:14:18 |
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*20];//?????
int tot;
int rt[N];
void clear(int x){ls(x)=rs(x)=sum(x)=0;}
void clear(){ls(0)=rs(0)=0,tot=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());
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
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: -100
Runtime Error
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 ...