#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());
struct node
{
int x, y;
int lazy_x, lazy_y;
int prior;
node *l, *r, *par;
node() {}
node(int _x, int _y)
{
x = _x;
y = _y;
lazy_x = lazy_y = -1;
prior = random_generator();
l = r = par = nullptr;
}
};
void push(node *t)
{
if (!t)
return;
if (t->lazy_x != -1)
{
t->x = t->lazy_x;
if (t->l)
t->l->lazy_x = t->lazy_x;
if (t->r)
t->r->lazy_x = t->lazy_x;
t->lazy_x = -1;
}
if (t->lazy_y != -1)
{
t->y = t->lazy_y;
if (t->l)
t->l->lazy_y = t->lazy_y;
if (t->r)
t->r->lazy_y = t->lazy_y;
t->lazy_y = -1;
}
}
void pull(node *t)
{
if (!t)
return;
t->par = nullptr;
if (t->l)
t->l->par = t;
if (t->r)
t->r->par = t;
}
void split(node *t, pair <int, int> x, node *&l, node *&r)
{
push(t);
if (!t)
{
l = r = nullptr;
return;
}
if (t->x > x.first || t->y > x.second)
split(t->l, x, l, t->l), r = t;
else
split(t->r, x, t->r, r), l = t;
pull(t);
}
void split1(node *t, pair <int, int> x, node *&l, node *&r)
{
push(t);
if (!t)
{
l = r = nullptr;
return;
}
if (x.first < t->x || (x.first == t->x && x.second < t->y))
split1(t->l, x, l, t->l), r = t;
else
split1(t->r, x, t->r, r), l = t;
pull(t);
}
void merge_op(node *l, node *r, node *&t)
{
push(l);
push(r);
if (!l || !r)
{
t = l ? l : r;
return;
}
if (l->prior > r->prior)
{
node *ll, *rr;
split1(r, make_pair(l->x, l->y - rand() % 2), ll, rr);
merge_op(l->l, ll, l->l);
merge_op(l->r, rr, l->r);
t = l;
pull(t);
}
else
{
node *ll, *rr;
split1(l, make_pair(r->x, r->y - rand() % 2), ll, rr);
merge_op(r->l, ll, r->l);
merge_op(r->r, rr, r->r);
t = r;
pull(t);
}
}
pair <int, int> leftmost(node *t)
{
push(t);
if (t->l)
return leftmost(t->l);
return {t->x, t->y};
}
struct treap
{
node *group;
int prior;
int x, y, min_y;
treap *l, *r;
treap() {}
treap(node *t)
{
group = t;
pair <int, int> curr = leftmost(t);
prior = random_generator();
x = curr.first;
y = min_y = curr.second;
l = r = nullptr;
}
};
void pull_treap(treap *t)
{
t->min_y = t->y;
if (t->l)
t->min_y = min(t->min_y, t->l->min_y);
if (t->r)
t->min_y = min(t->min_y, t->r->min_y);
}
void merge(treap *l, treap *r, treap *&t)
{
if (!l || !r)
{
t = l ? l : r;
return;
}
if (l->prior > r->prior)
merge(l->r, r, l->r), t = l;
else
merge(l, r->l, r->l), t = r;
pull_treap(t);
}
void split_treap(treap *t, int x, treap *&l, treap *&r)
{
if (!t)
{
l = r = nullptr;
return;
}
if (x < t->x)
split_treap(t->l, x, l, t->l), r = t;
else
split_treap(t->r, x, t->r, r), l = t;
pull_treap(t);
}
void insert(treap *&t, treap *x)
{
treap *l, *r;
split_treap(t, x->x - rand() % 2, l, r);
merge(l, x, l);
merge(l, r, t);
}
const int maxm = 500003;
node *where[maxm * 3];
treap *root = nullptr;
int n, m, q;
void read()
{
cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
where[i] = new node(x, y);
insert(root, new treap(where[i]));
}
}
pair <int, int> get(node *t)
{
int lazy_x = t->x, lazy_y = t->y;
while (t)
{
if (t->lazy_x != -1)
lazy_x = t->lazy_x;
if (t->lazy_y != -1)
lazy_y = t->lazy_y;
t = t->par;
}
return {lazy_x, lazy_y};
}
vector <treap*> to_add;
void clean1(treap *&x, int pos, node *&all)
{
if (!x)
return;
if (x->min_y > pos)
return;
clean1(x->l, pos, all);
clean1(x->r, pos, all);
pull_treap(x);
if (x->y <= pos)
{
node *l, *r;
split(x->group, {n-pos, pos}, l, r);
if (l)
l->lazy_x = n-pos;
merge_op(all, l, all);
if (r)
to_add.push_back(new treap(r));
merge(x->l, x->r, x);
}
}
void clean2(treap *&x, int pos, node *&all)
{
if (!x)
return;
if (x->min_y > n-pos)
return;
clean2(x->l, pos, all);
clean2(x->r, pos, all);
pull_treap(x);
if (x->y <= n-pos)
{
node *l, *r;
split(x->group, {pos, n-pos}, l, r);
if (l)
l->lazy_y = n-pos;
merge_op(all, l, all);
if (r)
to_add.push_back(new treap(r));
merge(x->l, x->r, x);
}
}
void solve()
{
int curr_idx = m + 1;
while (q--)
{
int type;
cin >> type;
if (type == 1)
{
int idx;
cin >> idx;
auto ans = get(where[idx]);
cout << ans.first << " " << ans.second << endl;
}
else
if (type == 2)
{
int x;
cin >> x;
node *all = nullptr;
to_add.clear();
treap *l, *r;
split_treap(root, n-x, l, r);
clean1(l, x, all);
merge(l, r, root);
if (all)
insert(root, new treap(all));
for (auto i: to_add)
insert(root, i);
}
else
if (type == 3)
{
int x;
cin >> x;
node *all = nullptr;
to_add.clear();
treap *l, *r;
split_treap(root, x, l, r);
clean2(l, x, all);
merge(l, r, root);
if (all)
insert(root, new treap(all));
for (auto i: to_add)
insert(root, i);
}
else
{
int x, y;
cin >> x >> y;
where[curr_idx] = new node(x, y);
insert(root, new treap(where[curr_idx]));
curr_idx++;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1004 KB |
Output is correct |
2 |
Correct |
6 ms |
748 KB |
Output is correct |
3 |
Correct |
7 ms |
876 KB |
Output is correct |
4 |
Correct |
10 ms |
876 KB |
Output is correct |
5 |
Correct |
11 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4751 ms |
128244 KB |
Output is correct |
2 |
Correct |
4655 ms |
137196 KB |
Output is correct |
3 |
Correct |
4730 ms |
137656 KB |
Output is correct |
4 |
Correct |
3600 ms |
111900 KB |
Output is correct |
5 |
Correct |
5010 ms |
127984 KB |
Output is correct |
6 |
Correct |
4584 ms |
123884 KB |
Output is correct |
7 |
Correct |
4900 ms |
134748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1916 ms |
76284 KB |
Output is correct |
2 |
Correct |
1646 ms |
70376 KB |
Output is correct |
3 |
Correct |
1263 ms |
77288 KB |
Output is correct |
4 |
Correct |
2425 ms |
101648 KB |
Output is correct |
5 |
Correct |
1754 ms |
72556 KB |
Output is correct |
6 |
Correct |
1552 ms |
69652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1916 ms |
76284 KB |
Output is correct |
2 |
Correct |
1646 ms |
70376 KB |
Output is correct |
3 |
Correct |
1263 ms |
77288 KB |
Output is correct |
4 |
Correct |
2425 ms |
101648 KB |
Output is correct |
5 |
Correct |
1754 ms |
72556 KB |
Output is correct |
6 |
Correct |
1552 ms |
69652 KB |
Output is correct |
7 |
Correct |
3825 ms |
92528 KB |
Output is correct |
8 |
Correct |
3787 ms |
101988 KB |
Output is correct |
9 |
Correct |
3741 ms |
102248 KB |
Output is correct |
10 |
Correct |
2781 ms |
99200 KB |
Output is correct |
11 |
Correct |
5990 ms |
126980 KB |
Output is correct |
12 |
Correct |
3216 ms |
89748 KB |
Output is correct |
13 |
Correct |
3500 ms |
91668 KB |
Output is correct |
14 |
Correct |
216 ms |
27900 KB |
Output is correct |
15 |
Correct |
1718 ms |
84640 KB |
Output is correct |
16 |
Correct |
3655 ms |
102252 KB |
Output is correct |
17 |
Correct |
3410 ms |
99816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1004 KB |
Output is correct |
2 |
Correct |
6 ms |
748 KB |
Output is correct |
3 |
Correct |
7 ms |
876 KB |
Output is correct |
4 |
Correct |
10 ms |
876 KB |
Output is correct |
5 |
Correct |
11 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
4751 ms |
128244 KB |
Output is correct |
8 |
Correct |
4655 ms |
137196 KB |
Output is correct |
9 |
Correct |
4730 ms |
137656 KB |
Output is correct |
10 |
Correct |
3600 ms |
111900 KB |
Output is correct |
11 |
Correct |
5010 ms |
127984 KB |
Output is correct |
12 |
Correct |
4584 ms |
123884 KB |
Output is correct |
13 |
Correct |
4900 ms |
134748 KB |
Output is correct |
14 |
Correct |
1916 ms |
76284 KB |
Output is correct |
15 |
Correct |
1646 ms |
70376 KB |
Output is correct |
16 |
Correct |
1263 ms |
77288 KB |
Output is correct |
17 |
Correct |
2425 ms |
101648 KB |
Output is correct |
18 |
Correct |
1754 ms |
72556 KB |
Output is correct |
19 |
Correct |
1552 ms |
69652 KB |
Output is correct |
20 |
Correct |
3825 ms |
92528 KB |
Output is correct |
21 |
Correct |
3787 ms |
101988 KB |
Output is correct |
22 |
Correct |
3741 ms |
102248 KB |
Output is correct |
23 |
Correct |
2781 ms |
99200 KB |
Output is correct |
24 |
Correct |
5990 ms |
126980 KB |
Output is correct |
25 |
Correct |
3216 ms |
89748 KB |
Output is correct |
26 |
Correct |
3500 ms |
91668 KB |
Output is correct |
27 |
Correct |
216 ms |
27900 KB |
Output is correct |
28 |
Correct |
1718 ms |
84640 KB |
Output is correct |
29 |
Correct |
3655 ms |
102252 KB |
Output is correct |
30 |
Correct |
3410 ms |
99816 KB |
Output is correct |
31 |
Correct |
3222 ms |
114008 KB |
Output is correct |
32 |
Correct |
4444 ms |
129504 KB |
Output is correct |
33 |
Correct |
2858 ms |
101844 KB |
Output is correct |
34 |
Correct |
6079 ms |
168888 KB |
Output is correct |
35 |
Correct |
6098 ms |
168816 KB |
Output is correct |
36 |
Correct |
3070 ms |
113656 KB |
Output is correct |
37 |
Correct |
7045 ms |
150608 KB |
Output is correct |
38 |
Correct |
4526 ms |
130488 KB |
Output is correct |
39 |
Correct |
4719 ms |
127096 KB |
Output is correct |
40 |
Correct |
4278 ms |
123652 KB |
Output is correct |