QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793615 | #21403. 文艺平衡树 | NOIPrpplusplus# | WA | 0ms | 3928kb | C++14 | 2.1kb | 2024-11-29 21:40:47 | 2024-11-29 21:40:48 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;
mt19937 rnd(time(0));
const int N = 1e5 + 5;
int n, m;
struct Toptree {
int rt, tot;
int lc[N], rc[N], sz[N], id[N], vl[N], lz[N];
#define ls(x) lc[x]
#define rs(x) rc[x]
int mk(int x) {
tot++;
sz[tot] = 1, id[tot] = rnd(), vl[tot] = x;
return tot;
}
void pup(int x) {
sz[x] = sz[ls(x)] + sz[rs(x)] + 1;
}
void plz(int x) {
lz[x] ^= 1;
swap(ls(x), rs(x));
}
void pdn(int x) {
if (lz[x]) {
plz(ls(x));
plz(rs(x));
lz[x] = 0;
}
}
void spl(int p, int k, int &x, int &y) {
if (!p) {
x = y = 0;
return;
}
pdn(p);
if (sz[ls(p)] + 1 <= k) {
x = p, spl(rs(x), k - sz[ls(p)] - 1, rs(x), y);
} else {
y = p, spl(ls(y), k, x, ls(y));
}
pup(p);
}
int mrg(int x, int y) {
if (!x || !y) {
return x + y;
}
pdn(x), pdn(y);
if (id[x] < id[y]) {
rs(x) = mrg(rs(x), y), pup(x);
return x;
} else {
ls(y) = mrg(x, ls(y)), pup(y);
return y;
}
}
void ins(int x) {
rt = mrg(rt, mk(x));
}
void rev(int l, int r) {
int x, y, z;
spl(rt, l - 1, x, y);
spl(y, r - l + 1, y, z);
plz(y);
rt = mrg(x, mrg(y, z));
}
void out(int x) {
if (!x) {
return;
}
out(ls(x));
cout << vl[x] << ' ';
out(rs(x));
}
} T;
void solve() {
cin >> n >> m;
F (i, 1, n) {
T.ins(i);
}
while (m--) {
int l, r;
cin >> l >> r;
T.rev(l, r);
}
T.out(T.rt);
}
bool Med;
int main() {
// FIO("");
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
int T = 1;
// cin >> T;
while (T--) solve();
cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3928kb
input:
30 5 7 26 7 18 5 9 4 15 3 15
output:
1 2 4 17 6 5 18 19 20 15 16 21 23 22 3 24 25 26 14 12 13 11 10 9 8 7 27 28 29 30
result:
wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 4 17 6 5 18 19 20 15 16 21... 12 13 11 10 9 8 7 27 28 29 30 '