QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#163069 | #7108. Couleur | hos_lyric | AC ✓ | 749ms | 14308kb | C++14 | 3.9kb | 2023-09-03 20:01:43 | 2023-09-03 20:01:43 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
template <class T> void bAdd(vector<T> &bit, int pos, const T &val) {
const int bitN = bit.size();
for (int x = pos; x < bitN; x |= x + 1) bit[x] += val;
}
template <class T> T bSum(const vector<T> &bit, int pos) {
T ret = 0;
for (int x = pos; x > 0; x &= x - 1) ret += bit[x - 1];
return ret;
}
template <class T> T bSum(const vector<T> &bit, int pos0, int pos1) {
return bSum(bit, pos1) - bSum(bit, pos0);
}
int N;
vector<int> A;
vector<Int> P;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &N);
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &A[i]);
--A[i];
}
P.resize(N);
for (int q = 0; q < N; ++q) {
scanf("%lld", &P[q]);
}
int V = 0;
vector<int> ids(N, -1);
vector<int> ls(N, -1), rs(N, -1);
vector<Int> cs(N, 0);
vector<vector<int>> bits(N);
multiset<Int> setC;
auto build = [&](int l, int r) -> int {
if (l == r) {
return -1;
}
const int u = V++;
vector<int> as(A.begin() + l, A.begin() + r);
sort(as.begin(), as.end());
const int asLen = as.size();
for (int i = l; i < r; ++i) {
A[i] = lower_bound(as.begin(), as.end(), A[i]) - as.begin();
ids[i] = u;
}
ls[u] = l;
rs[u] = r;
bits[u].assign(asLen, 0);
for (int i = r; --i >= l; ) {
cs[u] += bSum(bits[u], A[i]);
bAdd(bits[u], A[i], +1);
}
// cerr<<"build "<<l<<" "<<r<<": "<<cs[u]<<"; ";pv(A.begin()+l,A.begin()+r);
setC.insert(cs[u]);
return u;
};
build(0, N);
vector<Int> ans(N);
for (int q = 0; q < N; ++q) {
// cerr<<"setC = ";pv(setC.begin(),setC.end());
ans[q] = *setC.rbegin();
const int pos = (P[q] ^ ans[q]) - 1;
// cerr<<COLOR("33")<<"ans["<<q<<"] = "<<ans[q]<<", pos = "<<pos<<COLOR()<<endl;
const int u = ids[pos];
setC.erase(setC.find(cs[u]));
const int l = ls[u];
const int r = rs[u];
if (pos - l <= r - pos - 1) {
for (int i = l; i <= pos; ++i) {
bAdd(bits[u], A[i], -1);
cs[u] -= bSum(bits[u], A[i]);
}
build(l, pos);
ls[u] = pos + 1;
} else {
for (int i = r; --i >= pos; ) {
bAdd(bits[u], A[i], -1);
cs[u] -= ((i - l) - bSum(bits[u], A[i] + 1));
}
build(pos + 1, r);
rs[u] = pos;
}
setC.insert(cs[u]);
}
for (int q = 0; q < N; ++q) {
if (q) printf(" ");
printf("%lld", ans[q]);
}
puts("");
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3764kb
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: 749ms
memory: 14308kb
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