QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#162938 | #7108. Couleur | oscaryang# | AC ✓ | 1819ms | 28488kb | C++17 | 3.2kb | 2023-09-03 17:56:05 | 2023-09-03 17:56:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define vc vector
#define pb emplace_back
#define pii pair<int,int>
#define mkp make_pair
#define mkt make_tuple
#define mem(a) memset(a,0,sizeof(a))
//#define int long long
using namespace std;
const int N = 1e5+5, P = 998244353;
const int inf = 0x3f3f3f3f;
//const ll inf = 0x3f3f3f3f3f3f3f3f;
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch=='-'), ch = getchar();
while(isdigit(ch)) x = x*10+(ch^48), ch = getchar(); return w?-x:x;
}
inline void write(int x) { if(x<0) putchar('-'), x = -x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void writec(int x) { write(x); putchar(32); }
inline void writee(int x) { write(x); putchar(10); }
inline void inc(int &x,int y) { x += y-P; x += (x>>31)&P; }
inline void dec(int &x,int y) { x -= y; x += (x>>31)&P; }
inline int pls(int x,int y) { x += y-P; x += (x>>31)&P; return x; }
inline void Max(int &x,int y) { if(x<y) x = y; }
inline void Min(int &x,int y) { if(x>y) x = y; }
inline int power(int a,int b) { int res = 1; for(;b;b>>=1,a=1ll*a*a%P) if(b&1) res = 1ll*res*a%P; return res; }
int n, a[N], p[N];
set<tuple<int,int,ll> > o;
multiset<ll> S;
namespace sgt {
int tre[N*20], lc[N*20], rc[N*20], rt[N], idx = 1;
#define mid (l+r>>1)
inline void psu(int k) { tre[k] = tre[lc[k]]+tre[rc[k]]; }
inline void ins(int &k,int pr,int l,int r,int p) {
k = ++idx; lc[k] = lc[pr]; rc[k] = rc[pr]; tre[k] = tre[pr]+1;
if(l!=r) (p<=mid?ins(lc[k],lc[pr],l,mid,p):ins(rc[k],rc[pr],mid+1,r,p)), psu(k);
}
inline int ask(int x,int y,int l,int r,int L,int R) {
if(!x || L>R || L>r || R<l) return 0;
if(L<=l && R>=r) return tre[x]-tre[y];
return ask(lc[x],lc[y],l,mid,L,R)+ask(rc[x],rc[y],mid+1,r,L,R);
}
inline void reset() {
for(int i=0;i<=n;i++) rt[i] = 0;
for(int i=0;i<=idx;i++) tre[i] = lc[i] = rc[i] = 0;
idx = 0;
}
}
using namespace sgt;
inline void solve() {
n = read();
for(int i=1;i<=n;i++) a[i] = read();
for(int i=1;i<=n;i++) p[i] = read();
ll res = 0; S.clear(); o.clear();
for(int i=1;i<=n;i++)
ins(rt[i],rt[i-1],1,n,a[i]),
res += ask(rt[i],0,1,n,a[i]+1,n);
S.insert(res); o.insert(mkt(1,n,res));
for(int i=1,x;i<n;i++) {
printf("%lld ",res = *S.rbegin());
x = p[i]^res;
auto it = --o.upper_bound(mkt(x,inf,0));
auto [l,r,v] = *it;
o.erase(it); S.erase(S.lower_bound(v));
if(x-l+1<=r-x+1) {
res = 0;
for(int i=l;i<x;i++) res += ask(rt[i],rt[l-1],1,n,a[i]+1,n);
if(l<x) S.insert(res), o.insert(mkt(l,x-1,res));
res += ask(rt[x],rt[l-1],1,n,a[x]+1,n);
for(int i=l;i<=x;i++) res += ask(rt[r],rt[x],1,n,1,a[i]-1);
if(r>x) S.insert(v-res), o.insert(mkt(x+1,r,v-res));
}
else {
res = 0;
for(int i=x+1;i<=r;i++) res += ask(rt[r],rt[i],1,n,1,a[i]-1);
if(r>x) S.insert(res), o.insert(mkt(x+1,r,res));
res += ask(rt[r],rt[x],1,n,1,a[x]-1);
for(int i=x;i<=r;i++) res += ask(rt[x-1],rt[l-1],1,n,a[i]+1,n);
if(l<x) S.insert(v-res), o.insert(mkt(l,x-1,v-res));
}
}
puts("0"); reset();
}
signed main() {
//freopen("a.in","r",stdin);
int t = read(); while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5832kb
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: 1819ms
memory: 28488kb
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