// 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;
const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
struct node{
map<int, int> mp;
void add(int f, int s, int x){
auto L = mp.upper_bound(f);
int col = -1;
if(L != mp.begin())
col = prev(L)->S;
auto R = L;
while(R != mp.end() && (R->F) <= s)
col = R->S, R++;
mp[f] = x;
mp[s] = col;
}
int ask(int pos){
auto it = mp.upper_bound(pos);
if(it == mp.begin())
return -1;
return prev(it)->S;
}
};
struct node2{
node2 *L, *R;
node* s;
node2(){
L = R = 0;
s = 0;
}
void add(int fx, int sx, int fy, int sy, int x, int l = 0, int r = inf){
if(fx <= l && r <= sx){
if(s == 0)
s = new node();
s->add(fy, sy, x);
return;
}
int mid = (l+r) >> 1;
if(sx > l && mid > fx){
if(L == 0)
L = new node2();
L->add(fx, sx, fy, sy, x, l, mid);
}
if(sx > mid && r > fx){
if(R == 0)
R = new node2();
R->add(fx, sx, fy, sy, x, mid, r);
}
}
int ask(int posx, int posy, int l = 0, int r = inf){
int mid = (l+r) >> 1;
if(posx < mid){
int ans = -1;
if(s)
ans = s->ask(posy);
if(L)
ans = max(ans, L->ask(posx, posy, l, mid));
return ans;
}
else{
int ans = -1;
if(s)
ans = s->ask(posy);
if(R)
ans = max(ans, R->ask(posx, posy, mid, r));
return ans;
}
}
};
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<pii> to;
node2* rt;
void restart(){
mp.clear();
to.clear();
rt = new node2();
ins({0, N}, {0, 0});
}
pii color(pii p){
int c = rt->ask(p.F, p.S);
return to[c];
}
void put(pii l, pii r, pii x){
rt->add(l.F, r.F + 1, l.S, r.S + 1, sz(to));
to.PB(x);
}
void ins(pii a, pii b){
mp[a] = b;
put(b, trans(a), a);
}
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};
ins(A, p);
if(B.F <= B.S)
ins(B, {B.F, p.S});
}
else{
pii A = {L, x - 1}, B = {x, R};
ins(B, p);
if(A.F <= A.S)
ins(A, {p.F, N - A.S});
}
}
pii calc(pii p){
pii s = color(p);
pii A = mp[s], B = trans(s), C = trans2(s);
assert(A.F <= p.F && A.S <= p.S && p.F <= B.F && p.S <= B.S);
return {max(C.F, p.F), max(C.S, p.S)};
}
};
bigTraingle tr[20];
vector<int> ids[20];
int who[maxn];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int m, q;
cin >> N >> m >> q;
vector<pii> p;
for(int i = 0; i < 20; i++){
tr[i].restart();
if(bit(m, i)){
for(int j = 0; j < (1<<i); j++){
int x, y;
cin >> x >> y;
who[sz(p)] = i;
ids[i].PB(sz(p));
p.PB({x, y});
}
}
}
while(q--){
int task;
cin >> task;
if(task == 1){
int id;
cin >> id;
--id;
pii ans = tr[who[id]].calc(p[id]);
cout << ans.F << " " << ans.S << "\n";
}
if(task == 2){
int l;
cin >> l;
for(int i = 0; i < 20; i++)
if(!ids[i].empty())
tr[i].add(l, 1);
}
if(task == 3){
int l;
cin >> l;
for(int i = 0; i < 20; i++)
if(!ids[i].empty())
tr[i].add(l, 0);
}
if(task == 4){
int x, y;
cin >> x >> y;
vector<int> vv;
vv.PB(sz(p));
p.PB({x, y});
int pt = 0;
while(!ids[pt].empty()){
for(int x : ids[pt])
vv.PB(x), p[x] = tr[pt].calc(p[x]);
ids[pt].clear();
tr[pt].restart();
pt++;
}
swap(ids[pt], vv);
for(int x : ids[pt]){
who[x] = pt;
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
46716 KB |
Output is correct |
2 |
Correct |
119 ms |
53496 KB |
Output is correct |
3 |
Correct |
13 ms |
6272 KB |
Output is correct |
4 |
Correct |
81 ms |
40440 KB |
Output is correct |
5 |
Correct |
62 ms |
20344 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7254 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8089 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8089 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
46716 KB |
Output is correct |
2 |
Correct |
119 ms |
53496 KB |
Output is correct |
3 |
Correct |
13 ms |
6272 KB |
Output is correct |
4 |
Correct |
81 ms |
40440 KB |
Output is correct |
5 |
Correct |
62 ms |
20344 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Runtime error |
7254 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Halted |
0 ms |
0 KB |
- |