QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246532 | #7108. Couleur | ucup-team2190# | AC ✓ | 2035ms | 22320kb | C++20 | 3.2kb | 2023-11-10 21:49:03 | 2023-11-10 21:49:05 |
Judging History
answer
/**
* - Meet Brahmbhatt
* - Hard work always pays off
**/
#include"bits/stdc++.h"
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#ifdef MeetBrahmbhatt
#include "debug.h"
#else
#define dbg(...) 72
#endif
#define endl "\n"
#define ll long long
const long long INF = 4e18;
const int N = 1e5 + 10;
int a[N];
ll p[N];
pbds S[N];
int id[N];
int l[N], r[N];
ll cnt[N];
void solve() {
int n;
cin >> n;
for (int i = 0; i <= n; i++) {
S[i].clear();
id[i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 1; j <= n; j++) {
cin >> p[j];
}
auto get = [&] (int ID, int x, int val) {
if (val == 1) {
return (int) S[ID].size() - S[ID].order_of_key({x + 1, -1});
} else {
return S[ID].order_of_key({x, -1});
}
};
ll inv = 0;
for (int i = 1; i <= n; i++) {
inv += get(id[i], a[i], 1);
S[id[i]].insert({a[i], i});
}
l[0] = 1;
r[0] = n;
cnt[0] = inv;
multiset<ll> ans = {inv};
ll prv = inv;
cout << prv << " \n"[n == 1];
for (int i = 1; i < n; i++) {
int rem = (prv ^ p[i]);
assert(1 <= rem and rem <= n);
int cur_id = id[rem];
int L = l[cur_id];
int R = r[cur_id];
ll rem_inv = cnt[cur_id];
ll cur_inv = 0;
if (rem - L <= R - rem) {
l[i] = L;
r[i] = rem - 1;
l[cur_id] = rem + 1;
for (int j = L; j < rem; j++) {
id[j] = i;
int x = get(i, a[j], 1);
cur_inv += x;
S[i].insert({a[j], j});
S[cur_id].erase({a[j], j});
}
for (int j = L; j <= rem; j++) {
int x = get(cur_id, a[j], 0);
rem_inv -= x;
}
S[cur_id].erase({a[rem], rem});
} else {
l[i] = rem + 1;
r[i] = R;
r[cur_id] = rem - 1;
for (int j = rem + 1; j <= R; j++) {
id[j] = i;
int x = get(i, a[j], 1);
cur_inv += x;
S[i].insert({a[j], j});
S[cur_id].erase({a[j], j});
}
for (int j = rem; j <= R; j++) {
rem_inv -= get(cur_id, a[j], 1);
}
S[cur_id].erase({a[rem], rem});
}
rem_inv -= cur_inv;
ans.erase(ans.find(cnt[cur_id]));
cnt[i] = cur_inv;
cnt[cur_id] = rem_inv;
ans.insert(cur_inv);
ans.insert(rem_inv);
prv = *ans.rbegin();
cout << prv << " \n"[i == n - 1];
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(9);
int tt = 1;
cin >> tt;
while (tt--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 13772kb
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: 2035ms
memory: 22320kb
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