QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#456968 | #7108. Couleur | ucup-team3282 | AC ✓ | 2985ms | 60528kb | C++14 | 2.8kb | 2024-06-28 19:12:34 | 2024-06-28 19:12:35 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+9;
int root[N], n, a[N];
map<int, int> rev;// rev[a] stands for the rev of range beginning at id [a + 1]
multiset<int> s;
struct ChairmanTree {
int sum[N << 5], ch[N << 5][2], tot = 0;
int newnode() {
tot++;
sum[tot] = 0; ch[tot][0] = ch[tot][1] = 0;
return tot;
}
void add(int id, int l, int r, int old, int pos) {
sum[id] = sum[old]; ch[id][0] = ch[old][0]; ch[id][1] = ch[old][1];
int mid = (l + r) >> 1;
if (l == r) {sum[id]++; return;}
if (pos <= mid) add(ch[id][0] = newnode(), l, mid, ch[old][0], pos);
else add(ch[id][1] = newnode(), mid + 1, r, ch[old][1], pos);
sum[id] = sum[ch[id][0]] + sum[ch[id][1]];
}
int query(int id, int l, int r, int cl, int cr) {
if (cl > cr) return 0;
if (cl <= l && r <= cr) return sum[id];
int mid = (l + r) >> 1, res = 0;
if (cl <= mid) res += query(ch[id][0], l, mid, cl, cr);
if (mid < cr) res += query(ch[id][1], mid + 1, r, cl, cr);
return res;
}
} T;
void split(int l, int r, int x) {
int old = rev[l]; s.erase(s.find(old));
int ax = T.query(root[r - 1], 1, n, 1, a[x] - 1) - T.query(root[x], 1, n, 1, a[x] - 1)
+ T.query(root[x - 1], 1, n, a[x] + 1, n) - T.query(root[l], 1, n, a[x] + 1, n);
if (x - l < r - x) {
int one = 0, two = ax;//one is the rev of left; two is right
for (int i = l + 1; i < x; i++) {
one += T.query(root[i - 1], 1, n, a[i] + 1, n) - T.query(root[l], 1, n, a[i] + 1, n);
two += T.query(root[r - 1], 1, n, 1, a[i] - 1) - T.query(root[x], 1, n, 1, a[i] - 1);
}
rev[l] = one; rev[x] = old - one - two; s.insert(rev[l]); s.insert(rev[x]);
}
else {
int one = 0, two = ax;//one is the rev of right; two is left
for (int i = x + 1; i < r; i++) {
one += T.query(root[i - 1], 1, n, a[i] + 1, n) - T.query(root[x], 1, n, a[i] + 1, n);
two += T.query(root[x - 1], 1, n, a[i] + 1, n) - T.query(root[l], 1, n, a[i] + 1, n);
}
rev[l] = old - one - two; rev[x] = one; s.insert(rev[l]); s.insert(rev[x]);
}
}
void solve() {
T.tot = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) T.add(root[i] = T.newnode(), 1, n, root[i - 1], a[i]);
int ori = 0;
for (int i = 1; i <= n; i++) ori += T.query(root[i - 1], 1, n, a[i] + 1, n);
rev.clear(); rev[0] = ori; rev[n + 1] = 0;
s.clear(); s.insert(ori); s.insert(0);
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = *prev(s.end()); cout << ans;
if (i == n) cout << "\n";
else cout << " ";
int x; cin >> x;
x ^= ans;
auto it = prev(rev.lower_bound(x));
split(it->first, next(it)->first, x);
}
}
signed main() {
//freopen("G.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
int T; cin >> T;
while (T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7700kb
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: 2985ms
memory: 60528kb
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