QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#162510 | #7108. Couleur | GenshinImpactsFault# | AC ✓ | 1474ms | 31996kb | C++17 | 3.0kb | 2023-09-03 13:52:42 | 2023-09-03 13:52:43 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i, a, b) for(int i = a; i <= b; i ++)
#define REP(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch = getchar();
ll s = 0, w = 1;
while(ch < '0' || ch > '9'){if(ch == '-')w = -1; ch = getchar();}
while(ch >= '0' && ch <= '9'){s = s * 10 + ch - '0'; ch = getchar();}
return s * w;
}
#define N 100010
#define mid ((l + r) >> 1)
int n, a[N];
int p[N];
struct node
{
int l, r;
ll ans;
};
bool operator < (const node a, const node b){return a.l < b.l;}
multiset<ll>S;
set<node>sp;
int rt[N];
int sum[N << 5], ls[N << 5], rs[N << 5], cnt;
void add(int l, int r, int &x, int pos)
{
sum[++ cnt] = sum[x] + 1; ls[cnt] = ls[x]; rs[cnt] = rs[x]; x = cnt;
if(l == r)return ;
if(pos <= mid)add(l, mid, ls[x], pos);
else add(mid + 1, r, rs[x], pos);
}
int qry(int l, int r, int ql, int qr, int L, int R)
{
if(ql > qr)return 0;
if(l == ql && r == qr)return sum[R] - sum[L];
if(qr <= mid)return qry(l, mid, ql, qr, ls[L], ls[R]);
else if(ql > mid)return qry(mid + 1, r, ql, qr, rs[L], rs[R]);
else return qry(l, mid, ql, mid, ls[L], ls[R]) + qry(mid + 1, r, mid + 1, qr, rs[L], rs[R]);
}
ll ask(int l, int r)
{
ll ans = 0;
FOR(i, l, r - 1)ans += qry(1, n, 1, a[i] - 1, rt[i], rt[r]);
// cout << "GG:" << l <</ ' ' << r << ' ' << ans << endl;
return ans;
}
void add(int l, int r, ll num)
{
S.insert(num);
sp.insert((node){l, r, num});
}
ll qryans(){return (*S.rbegin());}
void era(int x)
{
assert(x >= 1 && x <= n);
auto it = sp.upper_bound((node){x, x, x});
assert(it != sp.begin()); it --;
int l = (*it).l, r = (*it).r; ll num = (*it).ans;
assert(l <= x && x <= r);
sp.erase(it); S.erase(S.lower_bound(num));
ll s = 0;
s = qry(1, n, a[x] + 1, n, rt[l - 1], rt[x - 1]) + qry(1, n, 1, a[x] - 1, rt[x], rt[r]);
num -= s;
ll vl, vr;
if(x - l + 1 <= r - x)
{
vl = ask(l, x - 1), vr = num - vl;
FOR(i, l, x - 1)vr -= qry(1, n, 1, a[i] - 1, rt[x], rt[r]);
}
else
{
vr = ask(x + 1, r), vl = num - vr;
FOR(i, x + 1, r)vl -= qry(1, n, a[i] + 1, n, rt[l - 1], rt[x - 1]);
}
if(l < x){sp.insert((node){l, x - 1, vl}); S.insert(vl);}
if(x < r){sp.insert((node){x + 1, r, vr}); S.insert(vr);}
}
void sol()
{
n = read();
FOR(i, 1, n)a[i] = read();
FOR(i, 1, n){rt[i] = rt[i - 1]; add(1, n, rt[i], a[i]);}
add(1, n, ask(1, n));
int T = n;
while(T --)
{
ll ans = qryans();
if(T)cout << ans << ' ';
else cout << ans << '\n';
ll x = read() ^ ans;
era(x);
}
sp.clear(); S.clear();
FOR(i, 1, cnt)ls[i] = rs[i] = sum[i] = 0; cnt = 0;
}
int main()
{
// freopen("G.out", "w", stdout);
int T = read();
while(T --)sol();
return 0;
}
/*
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
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3636kb
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: 1474ms
memory: 31996kb
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