QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168508 | #7108. Couleur | do_while_true | AC ✓ | 1821ms | 27704kb | C++20 | 4.2kb | 2023-09-08 16:28:01 | 2023-09-08 16:28:02 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
const int N=100010;
int n;
struct Node{
int l,r;
ll s;
bool operator<(const Node &y)const{
return l<y.l;
}
};
int rt[N],tot;
#define ls(x) tree[x].ls
#define rs(x) tree[x].rs
struct SGT{
int sum,ls,rs;
}tree[N*30];
void modify(int u,int &x,int l,int r,int p){
x=++tot;
tree[x]=tree[u];tree[x].sum++;
if(l==r)return ;
int mid=(l+r)>>1;
if(p<=mid)modify(ls(u),ls(x),l,mid,p);
else modify(rs(u),rs(x),mid+1,r,p);
return ;
}
int query(int x,int y,int tl,int tr,int l,int r){
if(!x&&!y)return 0;
if(tl>=l&&tr<=r)
return tree[y].sum-tree[x].sum;
int mid=(tl+tr)>>1,s=0;
if(mid>=l)s+=query(ls(x),ls(y),tl,mid,l,r);
if(mid<r)s+=query(rs(x),rs(y),mid+1,tr,l,r);
return s;
}
#undef ls
#undef rs
int a[N];
ll la;
void solve(){
read(n);
for(int i=1;i<=n;i++)read(a[i]);
set<Node>S;tot=0;la=0;
for(int i=1;i<=n;i++){
modify(rt[i-1],rt[i],1,n,a[i]);
if(a[i]<n)
la+=query(rt[0],rt[i-1],1,n,a[i]+1,n);
}
S.insert({1,n,la});
cout<<la<<' ';
multiset<ll>T;T.insert(la);
for(int i=1;i<=n;i++){
ll z;read(z);
int x=(z^la);
// int x=z;
if(i==n){
la=0;
// cout<<la<<'\n';
puts("");
break;
}
auto it=S.lower_bound({x+1,x+1,0});--it;
int l=it->l,r=it->r;ll s=it->s;
S.erase(it);T.erase(T.lower_bound(s));
if(l==r){
la=*(--T.end());
cout<<la<<' ';
continue;
}
if(x>l&&a[x]<n)
s-=query(rt[l-1],rt[x-1],1,n,a[x]+1,n);
if(x<r&&a[x]>1)
s-=query(rt[x],rt[r],1,n,1,a[x]-1);
if(x==l){
S.insert({l+1,r,s});
T.insert(s);
la=*(--T.end());
cout<<la<<' ';
continue;
}
if(x==r){
S.insert({l,r-1,s});
T.insert(s);
la=*(--T.end());
cout<<la<<' ';
continue;
}
int lsize=x-l,rsize=r-x;
if(lsize<rsize){
ll t=0;
for(int i=l;i<x;i++){
if(a[i]<n&&i>l)
t+=query(rt[l-1],rt[i-1],1,n,a[i]+1,n);
if(a[i]>1)
s-=query(rt[x],rt[r],1,n,1,a[i]-1);
}
s-=t;
S.insert({l,x-1,t});
S.insert({x+1,r,s});
T.insert(t);
T.insert(s);
}
else{
ll t=0;
for(int i=x+1;i<=r;i++){
if(a[i]<n&&i>x+1)
t+=query(rt[x],rt[i-1],1,n,a[i]+1,n);
if(a[i]<n)
s-=query(rt[l-1],rt[x-1],1,n,a[i]+1,n);
}
s-=t;
S.insert({l,x-1,s});
S.insert({x+1,r,t});
T.insert(s);
T.insert(t);
}
la=*(--T.end());
cout<<la<<' ';
}
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3400kb
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: 1821ms
memory: 27704kb
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