// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, pii> pi4;
const int maxn = 2e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
int N;
pii trans(pii p){ // x1 x2
return {p.S, N - p.F};
}
pii trans2(pii p){ // x1 x2
return {p.F, N - p.S};
}
struct bigTraingle{
map<pii, pii> mp;
vector<pair<pii, int> > v;
int sp[21][maxn];
void restart(){
mp.clear();
mp[{0, N}] = {0, 0};
}
pii color(pii p){
int L = upper_bound(v.begin(), v.end(), (pair<pii, int>){{p.F, inf}, inf}) - v.begin() - 1;
int R = upper_bound(v.begin(), v.end(), (pair<pii, int>){{N - p.S, inf}, inf}) - v.begin();
assert(L < R);
int lg = 31 - __builtin_clz(R-L);
int A = sp[lg][L], B = sp[lg][R - (1<<lg)];
if(v[B].S < v[A].S)
A = B;
return v[A].F;
}
void add(int l, bool is){
int x = l, y = N - l;
if(is)
swap(x, y);
auto it = --mp.upper_bound({x, inf});
int L = it->F.F, R = it->F.S;
pii p = it->S;
mp.erase(it);
if(!is){
pii A = {L, x}, B = {x + 1, R};
mp[A] = p;
if(B.F <= B.S)
mp[B] = {B.F, p.S};
}
else{
pii A = {L, x - 1}, B = {x, R};
mp[B] = p;
if(A.F <= A.S)
mp[A] = {p.F, N - A.S};
}
}
pii calc(pii p){
pii s = color(p);
pii C = trans2(s);
return {max(C.F, p.F), max(C.S, p.S)};
}
void prepare(){
v.clear();
for(auto x : mp){
v.PB({x.F, x.S.F + x.S.S});
}
assert(sz(v));
int Log = 31 - __builtin_clz(sz(v));
for(int i = 0; i < sz(v); i++)
sp[0][i] = i;
for(int i = 1; i <= Log; i++){
for(int j = 0; j < sz(v); j++){
sp[i][j] = sp[i-1][j];
int k = j + (1<<(i-1));
if(k < sz(v) && v[sp[i-1][j]].S > v[sp[i-1][k]].S)
sp[i][j] = sp[i-1][k];
}
}
}
};
int prog[maxn]; //////to Del
int LST[maxn];
vector<pii> conf, p, tell[maxn];
pii ans[maxn];
vector<int> tdo[4 * maxn];
void place(int f, int s, int x, int l = 0, int r = sz(conf) + 1, int id = 1){
if(f >= s || s <= l || r <= f)
return;
if(f <= l && r <= s){
tdo[id].PB(x);
return;
}
int mid = (l+r) >> 1;
place(f, s, x, l, mid, 2*id);
place(f, s, x, mid, r, 2*id+1);
}
bigTraingle tr;
void solve(int l = 0, int r = sz(conf) + 1, int id = 1){
if(r-l == 1){
for(pii x : tell[l]){
assert(prog[x.F] == l);
ans[x.S] = p[x.F];
}
}
if(r-l > 1){
int mid = (l+r) >> 1;
solve(l, mid, 2*id);
solve(mid, r, 2*id + 1);
}
if(r == sz(conf) + 1)
assert(tdo[id].empty());
if(tdo[id].empty())
return;
tr.restart();
for(int i = l; i < r; i++)
tr.add(conf[i].F, conf[i].S);
tr.prepare();
for(int i : tdo[id]){
assert(prog[i] == l);
prog[i] = r;
p[i] = tr.calc(p[i]);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int m, q;
cin >> N >> m >> q;
p.resize(m);
for(int i = 0; i < m; i++){
cin >> p[i].F >> p[i].S;
}
vector<pair<pii, int> > seg;
int Q = 0;
for(int i = 0; i < q; i++){
int task;
cin >> task;
if(task == 1){
int id;
cin >> id;
--id;
tell[sz(conf)].PB({id, Q++});
seg.PB({{LST[id], sz(conf)}, id});
LST[id] = sz(conf);
}
if(task == 2){
int l;
cin >> l;
conf.PB({l, 1});
}
if(task == 3){
int l;
cin >> l;
conf.PB({l, 0});
}
if(task == 4){
int x, y;
cin >> x >> y;
LST[sz(p)] = sz(conf);
prog[sz(p)] = sz(conf);
p.PB({x, y});
}
}
for(auto x : seg){
place(x.F.F, x.F.S, x.S);
}
solve();
for(int i = 0; i < Q; i++){
cout << ans[i].F << " " << ans[i].S << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
235768 KB |
Output is correct |
2 |
Correct |
149 ms |
235640 KB |
Output is correct |
3 |
Correct |
144 ms |
235512 KB |
Output is correct |
4 |
Correct |
149 ms |
235928 KB |
Output is correct |
5 |
Correct |
157 ms |
235512 KB |
Output is correct |
6 |
Correct |
145 ms |
235640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5525 ms |
342956 KB |
Output is correct |
2 |
Correct |
5531 ms |
363536 KB |
Output is correct |
3 |
Correct |
5252 ms |
363576 KB |
Output is correct |
4 |
Correct |
3362 ms |
362396 KB |
Output is correct |
5 |
Correct |
3503 ms |
363016 KB |
Output is correct |
6 |
Correct |
3118 ms |
360804 KB |
Output is correct |
7 |
Correct |
5717 ms |
363440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6437 ms |
349580 KB |
Output is correct |
2 |
Correct |
6500 ms |
350340 KB |
Output is correct |
3 |
Correct |
4861 ms |
353304 KB |
Output is correct |
4 |
Correct |
4905 ms |
350224 KB |
Output is correct |
5 |
Correct |
6689 ms |
350232 KB |
Output is correct |
6 |
Correct |
6814 ms |
350260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6437 ms |
349580 KB |
Output is correct |
2 |
Correct |
6500 ms |
350340 KB |
Output is correct |
3 |
Correct |
4861 ms |
353304 KB |
Output is correct |
4 |
Correct |
4905 ms |
350224 KB |
Output is correct |
5 |
Correct |
6689 ms |
350232 KB |
Output is correct |
6 |
Correct |
6814 ms |
350260 KB |
Output is correct |
7 |
Correct |
6656 ms |
350124 KB |
Output is correct |
8 |
Correct |
6644 ms |
350460 KB |
Output is correct |
9 |
Correct |
6626 ms |
350152 KB |
Output is correct |
10 |
Correct |
4802 ms |
353604 KB |
Output is correct |
11 |
Correct |
4984 ms |
350188 KB |
Output is correct |
12 |
Correct |
7214 ms |
357880 KB |
Output is correct |
13 |
Correct |
6902 ms |
350236 KB |
Output is correct |
14 |
Correct |
340 ms |
247124 KB |
Output is correct |
15 |
Correct |
736 ms |
294484 KB |
Output is correct |
16 |
Correct |
6623 ms |
350304 KB |
Output is correct |
17 |
Correct |
3268 ms |
349448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
235768 KB |
Output is correct |
2 |
Correct |
149 ms |
235640 KB |
Output is correct |
3 |
Correct |
144 ms |
235512 KB |
Output is correct |
4 |
Correct |
149 ms |
235928 KB |
Output is correct |
5 |
Correct |
157 ms |
235512 KB |
Output is correct |
6 |
Correct |
145 ms |
235640 KB |
Output is correct |
7 |
Correct |
5525 ms |
342956 KB |
Output is correct |
8 |
Correct |
5531 ms |
363536 KB |
Output is correct |
9 |
Correct |
5252 ms |
363576 KB |
Output is correct |
10 |
Correct |
3362 ms |
362396 KB |
Output is correct |
11 |
Correct |
3503 ms |
363016 KB |
Output is correct |
12 |
Correct |
3118 ms |
360804 KB |
Output is correct |
13 |
Correct |
5717 ms |
363440 KB |
Output is correct |
14 |
Correct |
6437 ms |
349580 KB |
Output is correct |
15 |
Correct |
6500 ms |
350340 KB |
Output is correct |
16 |
Correct |
4861 ms |
353304 KB |
Output is correct |
17 |
Correct |
4905 ms |
350224 KB |
Output is correct |
18 |
Correct |
6689 ms |
350232 KB |
Output is correct |
19 |
Correct |
6814 ms |
350260 KB |
Output is correct |
20 |
Correct |
6656 ms |
350124 KB |
Output is correct |
21 |
Correct |
6644 ms |
350460 KB |
Output is correct |
22 |
Correct |
6626 ms |
350152 KB |
Output is correct |
23 |
Correct |
4802 ms |
353604 KB |
Output is correct |
24 |
Correct |
4984 ms |
350188 KB |
Output is correct |
25 |
Correct |
7214 ms |
357880 KB |
Output is correct |
26 |
Correct |
6902 ms |
350236 KB |
Output is correct |
27 |
Correct |
340 ms |
247124 KB |
Output is correct |
28 |
Correct |
736 ms |
294484 KB |
Output is correct |
29 |
Correct |
6623 ms |
350304 KB |
Output is correct |
30 |
Correct |
3268 ms |
349448 KB |
Output is correct |
31 |
Correct |
4202 ms |
356300 KB |
Output is correct |
32 |
Correct |
5613 ms |
363508 KB |
Output is correct |
33 |
Correct |
5731 ms |
363516 KB |
Output is correct |
34 |
Correct |
5262 ms |
351816 KB |
Output is correct |
35 |
Correct |
5144 ms |
351532 KB |
Output is correct |
36 |
Correct |
4316 ms |
362372 KB |
Output is correct |
37 |
Correct |
4249 ms |
357636 KB |
Output is correct |
38 |
Correct |
5912 ms |
367644 KB |
Output is correct |
39 |
Correct |
5627 ms |
363304 KB |
Output is correct |
40 |
Correct |
6029 ms |
363644 KB |
Output is correct |