QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#448672 | #7108. Couleur | OneWan | AC ✓ | 3313ms | 48632kb | C++23 | 3.6kb | 2024-06-19 21:41:03 | 2024-06-19 21:41:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// 2023 OneWan
const int N = 1000005;
int n, a[N];
long long child[N << 5][2], sum[N << 5];
int tot;
int update(int L, int R, int old, int pos) {
int now = ++tot;
sum[now] = sum[old] + 1;
child[now][0] = child[old][0];
child[now][1] = child[old][1];
if (L == R) {
return now;
}
int mid = L + R >> 1;
if (pos <= mid) child[now][0] = update(L, mid, child[now][0], pos);
else child[now][1] = update(mid + 1, R, child[now][1], pos);
return now;
}
int query(int L, int R, int old, int QL, int QR) {
if (QL > QR) return 0;
if (QL <= L && R <= QR) {
return sum[old];
}
int mid = L + R >> 1;
int res = 0;
if (QL <= mid) {
res += query(L, mid, child[old][0], QL, QR);
}
if (QR > mid) {
res += query(mid + 1, R, child[old][1], QL, QR);
}
return res;
}
int root[N + 5];
struct Node {
int L, R;
long long res;
Node() = default;
Node(int L, int R, long long res) : L(L), R(R), res(res) {}
friend bool operator<(const Node &lhs, const Node &rhs) {
return lhs.L < rhs.L;
}
};
void solve() {
cin >> n;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
tot = 0;
for (int i = 1 ; i <= n ; i++) {
root[i] = update(1, n, root[i - 1], a[i]);
}
multiset<long long> ans;
set<Node> st;
{
long long res = 0;
for (int i = 1 ; i <= n ; i++) {
res += query(1, n, root[i - 1], a[i] + 1, n);
}
ans.insert(res);
st.emplace(1, n, res);
}
ans.insert(0LL);
ans.insert(0LL);
ans.insert(0LL);
ans.insert(0LL);
ans.insert(0LL);
for (int i = 1 ; i <= n ; i++) {
long long temp = *rbegin(ans);
cout << temp << " ";
long long x;
cin >> x;
if (i == n) break;
x ^= temp;
auto it = st.upper_bound(Node(x, x, 0));
if (it == begin(st)) continue;
it--;
auto [L, R, k] = *it;
st.erase(it);
ans.extract(k);
if (x - L <= R - x) {
long long res1 = 0, res2 = 0;
for (int j = L ; j < x ; j++) {
res1 += query(1, n, root[j - 1], a[j] + 1, n);
res1 -= query(1, n, root[L - 1], a[j] + 1, n);
res2 += query(1, n, root[R], 1, a[j] - 1);
res2 -= query(1, n, root[x], 1, a[j] - 1);
}
if (L <= x - 1) {
st.emplace(L, x - 1, res1);
ans.insert(res1);
}
if (x + 1 <= R) {
res2 = k - res1 - res2 - (query(1, n, root[R], 1, a[x] - 1) - query(1, n, root[x], 1, a[x] - 1)) - (query(1, n, root[x - 1], a[x] + 1, n) - query(1, n, root[L - 1], a[x] + 1, n));
st.emplace(x + 1, R, res2);
ans.insert(res2);
}
} else {
long long res1 = 0, res2 = 0;
for (int j = x + 1 ; j <= R ; j++) {
res1 += query(1, n, root[R], 1, a[j] - 1);
res1 -= query(1, n, root[j], 1, a[j] - 1);
res2 += query(1, n, root[x - 1], a[j] + 1, n);
res2 -= query(1, n, root[L - 1], a[j] + 1, n);
}
if (x + 1 <= R) {
st.emplace(x + 1, R, res1);
ans.insert(res1);
}
if (L <= x - 1) {
res2 = k - res1 - res2 - (query(1, n, root[x - 1], a[x] + 1, n) - query(1, n, root[L - 1], a[x] + 1, n)) - (query(1, n, root[R], 1, a[x] - 1) - query(1, n, root[x], 1, a[x] - 1));
st.emplace(L, x - 1, res2);
ans.insert(res2);
}
}
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: 3313ms
memory: 48632kb
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