QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#776624 | #7108. Couleur | Miguel03121 | TL | 1ms | 3624kb | C++17 | 3.3kb | 2024-11-23 19:45:17 | 2024-11-23 19:45:18 |
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;
const int N = 1e5 + 10;
#define lson rt << 1
#define rson rt << 1 | 1
#define int_mid int mid = (segTree[rt].l + segTree[rt].r) >> 1
ll b[N];
struct node {
int l, r;
ll val, lazy;
} segTree[N * 4];
ll helper(int l, int mid, int r) {
ll ans = 0;
ost found;
F(i, l, mid + 1) { found.insert({a[i], i}); }
F(i, mid + 1, r + 1) { ans += found.size() - found.order_of_key({a[i], i}); }
// cout << l << ' ' << mid << ' ' << r << ' ' << ans << endl;
return ans;
}
void push_up(int rt) {
segTree[rt].val = segTree[lson].val + segTree[rson].val;
segTree[rt].val += helper(segTree[rt].l, segTree[lson].r, segTree[rt].r);
}
void build(int rt, int l, int r) {
segTree[rt].l = l, segTree[rt].r = r;
segTree[rt].lazy = 0;
if (l == r) {
segTree[rt].val = 0;
return;
} else {
int mid = (l + r) >> 1;
build(lson, l, mid);
build(rson, mid + 1, r);
push_up(rt);
}
}
ll query_interval(int rt, int l, int r) {
if (l > r)
return 0;
if (l <= segTree[rt].l && r >= segTree[rt].r)
return segTree[rt].val;
int_mid;
if (r <= mid)
return query_interval(lson, l, r);
else if (l > mid)
return query_interval(rson, l, r);
return query_interval(lson, l, mid) + query_interval(rson, mid + 1, r) +
helper(l, mid, r);
}
ll inversions(int l, int r) { return query_interval(1, l, r); }
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]; }
build(1, 0, n - 1);
// cout << inversions(0, 1) << endl;
// cout << inversions(0, 2) << endl;
// cout << inversions(1, 3) << endl;
// cout << inversions(2, 4) << endl;
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 - 1), val2 = inversions(mid + 1, r - 1);
// cout << l << ' ' << mid - 1 << ' ' << val1 << endl;
// cout << mid + 1 << ' ' << r - 1 << ' ' << val2 << endl;
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: 1ms
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 ...