QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395086 | #7108. Couleur | ucup-team055# | TL | 0ms | 3640kb | C++23 | 2.5kb | 2024-04-21 03:31:24 | 2024-04-21 03:31:24 |
Judging History
answer
#include <bits/extc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < (b); i++)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(auto& a, auto b) { if(a >= b) return 0; a = b; return 1; }
using namespace __gnu_pbds;
template<class T> using pbds_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
struct T {
pbds_set<ll> s;
ll cost = 0;
void push_back(ll x) {
cost += sz(s) - s.order_of_key(x);
s.insert(x);
}
void pop_back(ll x) {
s.erase(x);
cost -= sz(s) - s.order_of_key(x);
}
void pop_front(ll x) {
s.erase(x);
cost -= s.order_of_key(x);
}
};
void solve() {
ll N;
cin >> N;
vector<ll> A(N), P(N);
for(ll& a : A) cin >> a;
{
vector<ll> idx(N);
rep(i, 0, N) idx[i] = i;
ranges::stable_sort(idx, {}, [&](ll i) { return A[i]; });
rep(i, 0, N) A[idx[i]] = i;
}
for(ll& a : P) cin >> a;
map<ll, ll> interval;
multiset<ll> costs {0};
vector<T> cc(N);
auto add = [&](ll l, ll r, T& t) {
if(l > r) return;
interval.emplace(l, r);
costs.insert(t.cost);
swap(cc[l], t);
};
auto push = [&](ll l, ll r) {
if(l > r) return;
interval[l] = r;
T t;
rep(i, l, r + 1) t.push_back(A[i]);
add(l, r, t);
};
auto rem = [&](ll l, ll r) {
auto& t = cc[l];
interval.erase(l);
costs.erase(costs.find(t.cost));
};
auto erase = [&](ll i) {
auto p = --interval.upper_bound(i);
auto [l, r] = *p;
T& t = cc[l];
rem(l, r);
if(r - i < i - l) {
for(ll j = r; j >= i; j--) t.pop_back(A[j]);
add(l, i - 1, t);
push(i + 1, r);
}
else {
rep(j, l, i + 1) t.pop_front(A[j]);
add(i + 1, r, t);
push(l, i - 1);
}
};
push(0, N - 1);
vector<ll> ans;
ll prev = 0;
for(ll p : P) {
prev = *rbegin(costs);
ans.push_back(prev);
p ^= prev;
p--;
erase(p);
}
rep(i, 0, N) cout << ans[i] << " \n"[i + 1 == N];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll T;
cin >> T;
while(T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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 0 0 0 0 0 0 ...