QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198812 | #7108. Couleur | ckiseki | AC ✓ | 2606ms | 34328kb | C++20 | 3.3kb | 2023-10-03 17:26:54 | 2023-10-03 17:26:54 |
Judging History
answer
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
template <typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
int64_t calc(vector<int> a) {
int64_t r = 0;
ordered_set<pair<int, int>> s;
for (int i = 0; i < int(a.size()); ++i) {
r += s.order_of_key({-a[i], -1});
s.insert({-a[i], i});
}
return r;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int &ai : a)
cin >> ai;
auto sub = [&a](int l, int r) {
vector<int> v;
for (int i = l; i < r; ++i)
v.push_back(a[i]);
return v;
};
priority_queue<pair<int64_t, int>> pq;
vector<int> idx(n);
int ctr = 0;;
vector<pair<int, int>> lr(n);
vector<pair<int64_t, ordered_set<pair<int, int>>>> v(n);
auto build = [&](int l, int r) {
lr[ctr] = {l, r};
ordered_set<pair<int, int>> s;
for (int i = l; i < r; ++i) {
idx[i] = ctr;
s.insert({a[i], i});
}
v[ctr] = {calc(sub(l, r)), s};
pq.emplace(v[ctr].first, ctr);
ctr += 1;
};
auto gao = [&](int p) {
int o = idx[p];
auto [l, r] = lr[o];
// [l, p)
// [p + 1, r)
if (p - l < r - (p + 1)) {
lr[o] = {p + 1, r};
if (l != p) {
build(l, p);
v[o].first -= v[idx[l]].first;
v[o].first -= v[idx[l]].second.size() - v[idx[l]].second.order_of_key({a[p], n});
}
for (int i = l; i <= p; ++i)
v[o].second.erase({a[i], i});
for (int i = l; i <= p; ++i)
v[o].first -= v[o].second.order_of_key({a[i], -1});
pq.emplace(v[o].first, o);
} else {
lr[o] = {l, p};
if (p + 1 != r) {
build(p + 1, r);
v[o].first -= v[idx[p + 1]].first;
v[o].first -= v[idx[p + 1]].second.order_of_key({a[p], -1});
}
for (int i = p; i < r; ++i)
v[o].second.erase({a[i], i});
for (int i = p; i < r; ++i)
v[o].first -= v[o].second.size() - v[o].second.order_of_key({a[i], n});
pq.emplace(v[o].first, o);
}
};
build(0, n);
for (int i = 0; i < n; ++i) {
while (not pq.empty()) {
if (v[pq.top().second].first != pq.top().first)
pq.pop();
else
break;
}
cout << pq.top().first << " \n"[i + 1 == n];
int64_t p;
cin >> p;
p ^= pq.top().first;
gao(p - 1);
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 2606ms
memory: 34328kb
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