#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 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)
swap(l, r);
node *ll, *rr;
split(r, make_pair(l->x, l->y), ll, rr);
merge_op(l->l, ll, l->l);
merge_op(l->r, rr, l->r);
t = l;
pull(t);
}
void print(node *x)
{
push(x);
if (!x)
return;
print(x->l);
cout << x->x << " " << x->y << endl;
print(x->r);
}
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};
}
const int maxm = 500003;
node *where[maxm * 3];
int n, m, q;
vector <node*> roots;
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);
roots.push_back(where[i]);
}
}
void op1(int x)
{
node *to_add = nullptr;
for (auto &i: roots)
{
node *l, *r;
split(i, {n-x, x}, l, r);
i = r;
if (!l)
continue;
l->lazy_x = n-x;
merge_op(to_add, l, to_add);
}
if (to_add)
roots.push_back(to_add);
}
void op2(int x)
{
node *to_add = nullptr;
for (auto &i: roots)
{
node *l, *r;
split(i, {x, n-x}, l, r);
i = r;
if (!l)
continue;
l->lazy_y = n-x;
merge_op(to_add, l, to_add);
}
if (to_add)
roots.push_back(to_add);
}
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;
op1(x);
}
else
if (type == 3)
{
int x;
cin >> x;
op2(x);
}
else
{
int x, y;
cin >> x >> y;
where[curr_idx++] = new node(x, y);
roots.push_back(where[curr_idx-1]);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
620 KB |
Output is correct |
2 |
Correct |
20 ms |
620 KB |
Output is correct |
3 |
Correct |
4 ms |
748 KB |
Output is correct |
4 |
Correct |
26 ms |
748 KB |
Output is correct |
5 |
Correct |
87 ms |
748 KB |
Output is correct |
6 |
Correct |
83 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18096 ms |
39848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18033 ms |
39696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18033 ms |
39696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
620 KB |
Output is correct |
2 |
Correct |
20 ms |
620 KB |
Output is correct |
3 |
Correct |
4 ms |
748 KB |
Output is correct |
4 |
Correct |
26 ms |
748 KB |
Output is correct |
5 |
Correct |
87 ms |
748 KB |
Output is correct |
6 |
Correct |
83 ms |
844 KB |
Output is correct |
7 |
Execution timed out |
18096 ms |
39848 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |