#include<iostream>
#include<algorithm>
#define rep(i, l, r, x) for(ll i = l; i != r; i += x)
#define max(x, y) (x > y ? x : y)
#define mx(x, y) (x = max(x, y))
#define X first
#define Y second
typedef int ll;
using namespace std;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pi;
constexpr ll xn = 1e6 + 5e5, xq = 1e6 + 5;
ll m1[xn << 2], m2[xn << 2], z1[xn << 2], z2[xn << 2], in[xn], ax[xq], ay[xq], o[xq], o1[xq], gt, prs;
pi q[xn], q1[xn];
void bld(ll v, ll l, ll r, ll l1, ll r1)
{
if(r <= l1 || r1 <= l) return;
m1[v] = m2[v] = z1[v] = z2[v] = -1;
if(r - l < 2) return;
ll m = (l + r) >> 1;
bld(v << 1, l, m, l1, r1), bld(v << 1 | 1, m, r, l1, r1);
}
inline void p1(ll v)
{
ll x = m1[v << 1], y = m1[v << 1 | 1];
if(x >= 0) mx(q[x].Y.X, z1[v]), mx(z1[v << 1], z1[v]);
if(y >= 0) mx(q[y].Y.X, z1[v]), mx(z1[v << 1 | 1], z1[v]);
z1[v] = -1;
}
inline void p2(ll v)
{
ll x = m2[v << 1], y = m2[v << 1 | 1];
if(x >= 0) mx(q[x].Y.Y, z2[v]), mx(z2[v << 1], z2[v]);
if(y >= 0) mx(q[y].Y.Y, z2[v]), mx(z2[v << 1 | 1], z2[v]);
z2[v] = -1;
}
void g1(ll v, ll l, ll r, ll l1, ll r1)
{
if(r <= l1 || r1 <= l) return;
if(l1 <= l && r <= r1)
{
if(m1[v] < 0) return;
if(gt < 0 || q[m1[v]].Y.X < q[gt].Y.X) gt = m1[v];
return;
}
if(z1[v] >= 0) p1(v);
ll m = (l + r) >> 1;
g1(v << 1, l, m, l1, r1), g1(v << 1 | 1, m, r, l1, r1);
}
void g2(ll v, ll l, ll r, ll l1, ll r1)
{
if(r <= l1 || r1 <= l) return;
if(l1 <= l && r <= r1)
{
if(m2[v] < 0) return;
if(gt < 0 || q[m2[v]].Y.Y < q[gt].Y.Y) gt = m2[v];
return;
}
if(z2[v] >= 0) p2(v);
ll m = (l + r) >> 1;
g2(v << 1, l, m, l1, r1), g2(v << 1 | 1, m, r, l1, r1);
}
inline void d1(ll v)
{
ll x = m1[v << 1], y = m1[v << 1 | 1];
m1[v] = (x < 0 ? y : y < 0 ? x : q[x].Y.X < q[y].Y.X ? x : y);
}
inline void d2(ll v)
{
ll x = m2[v << 1], y = m2[v << 1 | 1];
m2[v] = (x < 0 ? y : y < 0 ? x : q[x].Y.Y < q[y].Y.Y ? x : y);
}
void pt1(ll v, ll l, ll r, ll x, bool f)
{
if(x < l || r <= x) return;
if(r - l < 2)
{
m1[v] = -1;
if(f) m1[v] = x;
return;
}
if(z1[v] >= 0) p1(v);
ll m = (l + r) >> 1;
pt1(v << 1, l, m, x, f), pt1(v << 1 | 1, m, r, x, f), d1(v);
}
void pt2(ll v, ll l, ll r, ll x, bool f)
{
if(x < l || r <= x) return;
if(r - l < 2)
{
m2[v] = -1;
if(f) m2[v] = x;
return;
}
if(z2[v] >= 0) p2(v);
ll m = (l + r) >> 1;
pt2(v << 1, l, m, x, f), pt2(v << 1 | 1, m, r, x, f), d2(v);
}
void up1(ll v, ll l, ll r, ll l1, ll r1, ll x)
{
if(r <= l1 || r1 <= l) return;
if(l1 <= l && r <= r1)
{
ll y = m1[v];
if(y >= 0) mx(q[y].Y.X, x), mx(z1[v], x);
return;
}
ll m = (l + r) >> 1;
up1(v << 1, l, m, l1, r1, x), up1(v << 1 | 1, m, r, l1, r1, x);
}
void up2(ll v, ll l, ll r, ll l1, ll r1, ll x)
{
if(r <= l1 || r1 <= l) return;
if(l1 <= l && r <= r1)
{
ll y = m2[v];
if(y >= 0) mx(q[y].Y.Y, x), mx(z2[v], x);
return;
}
ll m = (l + r) >> 1;
up2(v << 1, l, m, l1, r1, x), up2(v << 1 | 1, m, r, l1, r1, x);
}
void doj(ll l, ll r, ll d, ll x, ll y, ll n)
{
ll l1 = l, r1 = r;
if(r1 < l1) swap(l1, r1), l1++, r1++;
if(r1 <= l1) return;
bld(1, 0, prs, l1, r1);
ll a1 = l1, a2 = r1 - 1, r2 = 0, c2 = 0;
if(n > 0) r2 = c2 = 1;
if(n > 1) r2 = (n + 1) >> 1, c2 = n >> 1;
rep(i, l, r, d)
{
if(o[i] == 1)
{
ll a = in[q[i].X], b = q[i].Y.X;
if(a < -1) q1[a1] = q[i], o1[a1++] = 1;
else if(a < 0) q1[a2] = q[i], o1[a2--] = 1;
if(a >= 0) g1(1, 0, prs, a, a + 1), g2(1, 0, prs, a, a + 1);
ax[b] = q[a].Y.X, ay[b] = q[a].Y.Y;
}
if(o[i] == 2)
{
ll a = q[i].X;
if(r2 <= a)
{
if(r2 < a) q1[a2] = {a - r2, {0, 0}}, o1[a2--] = 2;
up1(1, 0, prs, l1, r1, x + n - a);
}
else
{
q1[a1] = q[i], o1[a1++] = 2;
while(1)
{
gt = -1, g2(1, 0, prs, l1, r1);
if(gt < 0 || q[gt].Y.Y > y + a) break;
pt1(1, 0, prs, gt, 0), pt2(1, 0, prs, gt, 0);
pi p = q[gt];
q1[a1] = {p.X, {x - a + n, p.Y.Y}}, o1[a1++] = 4, in[p.X] = -2;
}
}
}
if(o[i] == 3)
{
ll a = q[i].X;
if(c2 <= a)
{
if(c2 < a) q1[a1] = {a - c2, {0, 0}}, o1[a1++] = 3;
up2(1, 0, prs, l1, r1, y + n - a);
}
else
{
q1[a2] = q[i], o1[a2--] = 3;
while(1)
{
gt = -1, g1(1, 0, prs, l1, r1);
if(gt < 0 || q[gt].Y.X > x + a) break;
pt1(1, 0, prs, gt, 0), pt2(1, 0, prs, gt, 0);
pi p = q[gt];
q1[a2] = {p.X, {p.Y.X, y - a + n}}, o1[a2--] = 4, in[p.X] = -1;
}
}
}
if(o[i] == 4)
{
pi p = q[i];
if(p.Y.X > x + c2) q1[a1] = p, in[p.X] = -2, o1[a1++] = 4;
else if(p.Y.Y > y + r2) q1[a2] = p, in[p.X] = -1, o1[a2--] = 4;
else pt1(1, 0, prs, i, 1), pt2(1, 0, prs, i, 1);
}
}
rep(i, l, r, d)
{
q[i] = q1[i], o[i] = o1[i];
if(o[i] == 4) in[q[i].X] = i;
}
if(n < 2) doj(l1, a1, 1, x + 1, y, 0), doj(r1 - 1, a2, -1, x, y + 1, 0);
else doj(l1, a1, 1, x + c2, y, r2), doj(r1 - 1, a2, -1, x, y + r2, c2);
}
int main()
{
ll n, m, Q;
cin >> n >> m >> Q;
rep(i, 0, m, 1)
{
ll x, y;
cin >> x >> y;
q[i] = {i, {x, y}}, in[i] = i, o[i] = 4;
}
ll cnt = m, ca = 0;
rep(i, m, m + Q, 1)
{
cin >> o[i];
if(o[i] < 4) cin >> q[i].X;
else
{
cin >> q[i].Y.X >> q[i].Y.Y;
in[cnt] = i, q[i].X = cnt++;
}
if(o[i] == 1) q[i].X--, q[i].Y.X = ca++;
}
prs = m + Q, doj(0, prs, 1, 0, 0, n);
rep(i, 0, ca, 1)
{
cout << ax[i] << ' ' << ay[i];
if(i < ca - 1) cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1069 ms |
221432 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
990 ms |
220960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
990 ms |
220960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |