QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220587 | #7108. Couleur | salvator_noster# | AC ✓ | 1862ms | 38148kb | C++20 | 6.7kb | 2023-10-20 16:03:05 | 2023-10-20 16:03:05 |
Judging History
answer
#include <bits/stdc++.h>
template <class T>
inline int qlog(T a) {
double x = a;
return ((*(long long*) & x) >> 52 & 2047) - 1023;
}
#define fopen LilyWhite
void fopen(const char *s) {
static char filename[32];
sprintf(filename, "%s.in", s);
freopen(filename, "r", stdin);
sprintf(filename, "%s.out", s);
freopen(filename, "w", stdout);
}
typedef unsigned int u32;
typedef long long ll;
typedef unsigned long long u64;
#define Please return
#define AC 0
#define cin Mizuhashi
#define cout Parsee
#define endl '\n'
class Reader{
private:
static const int BUF_SIZE = 1 << 22;
char BUF_R[BUF_SIZE], *csy1, *csy2;
#ifndef _LOCAL_RUNNING
#define GC (csy1 == csy2 && (csy2 = (csy1 = BUF_R) + fread(BUF_R, 1, BUF_SIZE, stdin), csy1 == csy2) ? EOF : *csy1 ++)
#else
char cur;
#define GC (cur = getchar())
#endif
#define IL inline
public:
IL bool eof() {
#ifndef _LOCAL_RUNNING
return csy1 == csy2 && (csy2 = (csy1 = BUF_R) + fread(BUF_R, 1, BUF_SIZE, stdin), csy1 == csy2);
#else
return cur == EOF;
#endif
}
template <class Ty>
IL Reader& operator >> (Ty &t) {
int u = 0;
char c = GC;
for (t = 0; c < 48 || c > 57; c = GC)
if (c == EOF) break;
else if (c == '-') u = 1;
for ( ; c > 47 && c < 58; c = GC) t = t * 10 + (c ^ 48);
t = u ? -t : t; return *this;
}
IL Reader& operator >> (double &t) {
int tmp, u = 0; char c = GC;
for (tmp = 0; c < 48 || c > 57; c = GC)
if (c == EOF) break;
else if (c == '-') u = 1;
for ( ; c > 47 && c < 58; c = GC) tmp = tmp * 10 + (c ^ 48);
t = (tmp = u ? -tmp : tmp);
if (c == '.') {
double x = 1;
for (c = GC; c > 47 && c < 58; c = GC) t += (x /= 10) * (c ^ 48);
}
return *this;
}
IL Reader& operator >> (char *s) {
char c = GC;
for (*s = 0; c < 33; c = GC) if (c == EOF) return *this;
for ( ; c > 32; c = GC) *s ++ = c;
*s = 0; return *this;
}
IL Reader& operator >> (char &c) {
for (c = GC; c < 33; c = GC) if (c == EOF) return *this;
return *this;
}
}cin;
class Writer{
private:
static const int BUF_SIZE = 1 << 22;
char BUF_W[BUF_SIZE], *csy;
#define IL inline
inline void WC(const char c) {
if (csy - BUF_W == BUF_SIZE) fwrite(BUF_W, 1, BUF_SIZE, stdout), csy = BUF_W;
*csy ++ = c;
}
public:
Writer() : csy(BUF_W) {}
~ Writer() {fwrite(BUF_W, 1, csy - BUF_W, stdout);}
IL void flush() {fwrite(BUF_W, 1, csy - BUF_W, stdout); csy = BUF_W;}
template <class Ty>
IL Writer& operator << (Ty x) {
static int sta[32], top;
if (x < 0) {
WC('-');
do sta[top ++] = - (x % 10); while (x /= 10);
}else do sta[top ++] = x % 10; while (x /= 10);
while (top) WC(sta[-- top] ^ 48);
return *this;
}
IL Writer& operator << (const char &c) {WC(c); return *this;}
IL Writer& operator << (const char *s) {while (*s) WC(*s ++); return *this;}
}cout;
using namespace std;
typedef pair <int, int> pii;
const int MAX_N = 100000 + 5;
const int MAX_M = 5000000;
int N, a[MAX_N];
struct Node{
int l, r;
ll res;
inline bool operator < (const Node &comp) const {
return l < comp.l;
}
};
set <Node> s;
multiset <ll> inv;
struct SegmentNode{
int ls, rs, sum;
}node[MAX_M];
int rt[MAX_N], pool[MAX_M], poolSize, tot;
ll res0;
int NewNode() {
int u = poolSize ? pool[poolSize --] : ++ tot;
node[u].ls = 0; node[u].rs = 0; node[u].sum = 0;
return u;
}
void DeleteNode(int &u) {
pool[++ poolSize] = u; u = 0;
}
void segment_modify(int &i, int l, int r, int x, int v) {
i = i ? i : NewNode();
node[i].sum += v;
if (l != r) {
int mid = l + r >> 1;
mid < x ? segment_modify(node[i].rs, mid + 1, r, x, v) : segment_modify(node[i].ls, l, mid, x, v);
}
if (!node[i].sum) DeleteNode(i);
}
int segment_query(int i, int l, int r, int ql, int qr) {
if (!i || qr < ql) return 0;
if (l < ql || r > qr) {
int mid = l + r >> 1, res = 0;
if (ql <= mid) res += segment_query(node[i].ls, l, mid, ql, qr);
if (mid < qr) res += segment_query(node[i].rs, mid + 1, r, ql, qr);
return res;
}else {
return node[i].sum;
}
}
void modify(int p) {
auto it = -- s.upper_bound({p, N, 0});
int l = it -> l, r = it -> r;
ll cnt = it -> res;
s.erase(it); inv.erase(inv.find(cnt));
segment_modify(rt[l], 1, N, a[p], -1);
ll resl, resr;
// fprintf(stderr, "l = %d, r = %d, p = %d\n", l, r, p);
if (p - l < r - p) {
rt[p + 1] = rt[l];
rt[l] = 0;
resl = 0; resr = cnt;
for (int i = l; i < p; i ++) segment_modify(rt[p + 1], 1, N, a[i], -1);
for (int i = l; i < p; i ++) {
segment_modify(rt[l], 1, N, a[i], 1);
resr -= segment_query(rt[p + 1], 1, N, 1, a[i] - 1);
resl += segment_query(rt[l], 1, N, a[i] + 1, N);
}
resr -= segment_query(rt[p + 1], 1, N, 1, a[p] - 1) + segment_query(rt[l], 1, N, a[p] + 1, N) + resl;
}else {
rt[p + 1] = 0;
resl = cnt; resr = 0;
for (int i = p + 1; i <= r; i ++) segment_modify(rt[l], 1, N, a[i], -1);
for (int i = p + 1; i <= r; i ++) {
segment_modify(rt[p + 1], 1, N, a[i], 1);
resl -= segment_query(rt[l], 1, N, a[i] + 1, N);
resr += segment_query(rt[p + 1], 1, N, a[i] + 1, N);
}
resl -= segment_query(rt[p + 1], 1, N, 1, a[p] - 1) + segment_query(rt[l], 1, N, a[p] + 1, N) + resr;
}
// fprintf(stderr, "resl = %lld, resr = %lld\n", resl, resr);
if (l < p) s.insert({l, p - 1, resl}), inv.insert(resl);
if (p < r) s.insert({p + 1, r, resr}), inv.insert(resr);
}
void solve() {
cin >> N;
s.clear();
poolSize = tot = 0;
res0 = 0; rt[1] = 0;
for (int i = 1; i <= N; i ++) {
cin >> a[i];
res0 += segment_query(rt[1], 1, N, a[i] + 1, N);
segment_modify(rt[1], 1, N, a[i], 1);
}
s.insert({1, N, res0});
cout << res0;
ll last_ans = res0;
inv.clear(); inv.insert(res0);
for (int i = 1; i <= N; i ++) {
ll p; cin >> p;
if (i < N) {
p ^= last_ans;
modify(p);
last_ans = *(-- inv.end());
cout << ' ' << last_ans;
}else {
cout << endl;
}
}
}
int main() {
int T;
cin >> T;
while (T --) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9792kb
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: 1862ms
memory: 38148kb
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