QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#156997 | #7108. Couleur | ucup-team896# | AC ✓ | 2911ms | 59952kb | C++14 | 3.1kb | 2023-09-02 14:44:15 | 2023-09-02 14:59:41 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using namespace std;
const int N = 100010;
const int M = N * 30;
struct fwt {
ll t[N];
int n;
void upd(int x, int v) {
while (x <= n) t[x] += v, x += x & (-x);
}
ll qry(int x) {
ll res = 0;
while (x) res += t[x], x -= x & (-x);
return res;
}
} fwt;
int n, a[N], rt[N], ls[M], rs[M], tot;
ll t[M];
ll p[N];
set<pii> s;
multiset<ll> S;
map<pii, ll> mp;
ll inv(int l, int r) {
ll res = 0;
per (i, r, l) res += fwt.qry(a[i] - 1), fwt.upd(a[i], 1);
rep (i, l, r) fwt.upd(a[i], -1);
return res;
}
#define mid ((l + r) >> 1)
void upd(int &p, int q, int l, int r, int x) {
p = ++tot, t[p] = t[q] + 1, ls[p] = ls[q], rs[p] = rs[q];
if (l == r) return;
if (x <= mid) upd(ls[p], ls[q], l, mid, x);
else upd(rs[p], rs[q], mid + 1, r, x);
}
ll qry(int p, int l, int r, int x, int y) {
if (!p || x > y) return 0;
if (l == x && r == y) return t[p];
if (y <= mid) return qry(ls[p], l, mid, x, y);
else if (x > mid) return qry(rs[p], mid + 1, r, x, y);
else return qry(ls[p], l, mid, x, mid) + qry(rs[p], mid + 1, r, mid + 1, y);
}
#undef mid
void work() {
cin >> n;
rep (i, 1, n) cin >> a[i];
rep (i, 1, n) cin >> p[i];
s.clear(), s.insert(pii(1, n));
tot = 0, fwt.n = n;
rep (i, 1, n) upd(rt[i], rt[i - 1], 1, n, a[i]);
ll res = inv(1, n);
S.clear(), S.insert(res);
mp.clear(), mp[pii(1, n)] = res;
rep (i, 1, n) {
res = *prev(S.end());
cout << res, p[i] ^= res;
if(i != n) cout << " ";
auto it = prev(s.upper_bound(pii(p[i], 1e9)));
int l = it -> fi, r = it -> se;
s.erase(it);
ll lst = mp[pii(l, r)];
S.erase(S.find(lst));
lst -= qry(rt[r], 1, n, 1, a[p[i]] - 1) - qry(rt[p[i]], 1, n, 1, a[p[i]] - 1);
lst -= qry(rt[p[i] - 1], 1, n, a[p[i]] + 1, n) - qry(rt[l - 1], 1, n, a[p[i]] + 1, n);
int lt = p[i] - 1, rr = p[i] + 1;
if (lt - l < r - rr) {
rep (j, l, lt) lst -= qry(rt[r], 1, n, 1, a[j] - 1) - qry(rt[rr - 1], 1, n, 1, a[j] - 1);
ll L = inv(l, lt), R = lst - L;
mp[pii(l, lt)] = L, mp[pii(rr, r)] = R;
S.insert(L), S.insert(R);
} else {
rep (j, rr, r) lst -= qry(rt[lt], 1, n, a[j] + 1, n) - qry(rt[l - 1], 1, n, a[j] + 1, n);
ll R = inv(rr, r), L = lst - R;
mp[pii(l, lt)] = L, mp[pii(rr, r)] = R;
S.insert(L), S.insert(R);
}
s.insert(pii(l, lt)), s.insert(pii(rr, r));
}
cout << '\n';
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) work();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7864kb
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: 2911ms
memory: 59952kb
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