QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64776 | #21403. 文艺平衡树 | zhoukangyang# | WA | 2ms | 5648kb | C++11 | 1.5kb | 2022-11-25 15:43:53 | 2022-11-25 15:44:38 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
using namespace std;
const int N = 2e6 + 7;
int n, m;
mt19937_64 orz(time(0) ^ clock());
ull key[N];
int siz[N], ch[N][2];
bool tag[N];
void rev(int x) {
if(x) tag[x] ^= 1, swap(ch[x][0], ch[x][1]);
}
void push(int x) {
if(tag[x]) rev(ch[x][0]), rev(ch[x][1]), tag[x] = 0;
}
void upd(int x) {
siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1;
}
void split(int now, int k, int &x, int &y) {
if(!now) return x = y = 0, void();
push(now);
if(siz[ch[now][0]] < k)
x = now, split(ch[x][1], k - siz[ch[x][0]] - 1, ch[x][1], y), upd(x);
else y = now, split(ch[y][0], k, x, ch[y][0]), upd(y);
}
int merge(int x, int y) {
if(!x || !y) return x + y;
push(x), push(y);
if(key[x] < key[y]) return ch[x][1] = merge(ch[x][1], y), upd(x), x;
else return ch[y][0] = merge(x, ch[y][0]), upd(y), y;
}
int rt;
void dfs(int x) {
if(!x) return ;
dfs(ch[x][0]);
cout << x << ' ';
dfs(ch[x][1]);
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
L(i, 1, n)
key[i] = orz(), upd(i), rt = merge(rt, i);
while(m--) {
int l, r;
cin >> l >> r;
int spx, spy;
split(rt, r, spx, spy);
split(spx, l - 1, spx, rt);
rev(rt);
rt = merge(merge(spx, rt), spy);
}
dfs(rt);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5556kb
input:
30 5 7 26 7 18 5 9 4 15 3 15
output:
1 2 4 17 16 15 6 5 18 19 20 21 22 23 3 24 25 26 14 13 12 11 10 9 8 7 27 28 29 30
result:
ok single line: '1 2 4 17 16 15 6 5 18 19 20 21... 13 12 11 10 9 8 7 27 28 29 30 '
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 5648kb
input:
100 10 9 29 10 68 7 72 15 73 57 79 4 39 11 69 45 61 1 42 15 21
output:
47 4 5 46 45 44 43 42 40 41 39 38 37 36 78 33 32 31 79 34 35 77 76 54 18 19 20 21 22 23 24 74 75 53 52 51 49 48 50 3 2 1 6 72 63 64 65 66 67 29 68 8 27 26 25 73 7 28 69 70 71 62 61 60 59 58 57 56 55 17 16 15 14 13 11 12 10 9 30 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
result:
wrong answer 1st lines differ - expected: '5 4 47 46 45 44 43 42 41 40 39... 91 92 93 94 95 96 97 98 99 100', found: '47 4 5 46 45 44 43 42 40 41 39...91 92 93 94 95 96 97 98 99 100 '