QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#776164 | #7108. Couleur | Miguel03121 | TL | 0ms | 3624kb | C++17 | 1.8kb | 2024-11-23 17:45:30 | 2024-11-23 17:45:30 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h> // pbds
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(0)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
vector<int> a;
ll inversions(int l, int r) {
ost found;
ll ans = 0;
F(i, l, r) {
ans += found.size() - found.order_of_key({a[i], i});
found.insert({a[i], i});
}
return ans;
}
signed main() {
IOS;
cin.tie(0), cout.tie(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
a.resize(n);
F(i, 0, n) { cin >> a[i]; }
vi z(n);
F(i, 0, n) { cin >> z[i]; }
map<ii, ll> values;
set<pair<ll, ii>> sorted;
set<int> removed({-1, n});
values[{0, n}] = inversions(0, n);
sorted.insert({values[{0, n}], {0, n}});
ll ans = sorted.rbegin()->first;
cout << ans << ' ';
F(i, 0, n - 1) {
z[i] ^= ans;
int mid = z[i] - 1;
auto it = removed.upper_bound(mid);
int r = *it, l = *(--it) + 1;
// cout << l << ' ' << mid << ' ' << r << endl;
sorted.erase({values[{l, r}], {l, r}});
values.erase({l, r});
removed.insert(mid);
ll val1 = inversions(l, mid), val2 = inversions(mid + 1, r);
values[{l, mid}] = val1, sorted.insert({val1, {l, mid}});
values[{mid + 1, r}] = val2, sorted.insert({val2, {mid + 1, r}});
ans = sorted.rbegin()->first;
cout << ans << ' ';
}
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: -100
Time Limit Exceeded
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 ...