#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6+5;
struct bla{
int answer = 1e9;
int l = -1;
int r = -1;
};
bla tree[2*N+100];
multiset<int>b[N],e[N],L,R;
inline void go(int x,int y,int &l,int &r,int &answer){
if(x != -1){
if(x == -2) l = -1; else
if(l == -1) l = x; else l = max(l, x);
}
if(y != -1){
if(y == -2) r = -1; else
if(r == -1) r = y; else r = min(r, y);
}
if(x == -2 || y == -2){
answer = 1e9;
return ;
}
if(l != -1 && r != -1){
answer = r - l;
}
}
inline int mn(int x,int y){
if(x == -1) return y;
if(y == -1) return x;
return min(x,y);
}
inline int mx(int x,int y){
if(x == -1) return y;
if(y == -1) return x;
return max(x,y);
}
inline int get(int y,int x){
if(x == -1 || y == -1){
return 1e9;
}
return y - x;
}
inline void upd(int node,int tl,int tr,int pos,int x,int y){
if(tl == tr){
go(x,y,tree[node].l,tree[node].r,tree[node].answer);
//cout << tl << " --- " << tr << " : " << tree[node].l << " " << tree[node].r << endl;
return ;
}
int mid = tl + tr; mid >>= 1;
int left = node<<1; int right = left|1;
if(pos <= mid){
upd(left,tl,mid,pos,x,y);
} else {
upd(right,mid+1,tr,pos,x,y);
}
tree[node].l = mx(tree[left].l,tree[right].l);
tree[node].r = mn(tree[left].r,tree[right].r);
//cout << tl << " --- " << tr << " : " << tree[node].l << " and " << tree[node].r << endl;
tree[node].answer = get(tree[right].r, tree[left].l);
tree[node].answer = min(tree[node].answer, min(tree[left].answer, tree[right].answer));
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int q;
cin >> q;
while(q--){
char c;
int l,r;
cin >> c >> l >> r;
if(c == 'A'){
b[l].insert(r);
e[r].insert(l);
L.insert(l);
R.insert(r);
} else {
b[l].erase(b[l].find(r));
e[r].erase(e[r].find(l));
L.erase(L.find(l));
R.erase(R.find(r));
}
int val;
if(b[l].size()) val = *b[l].rbegin(); else val = -2;
upd(1,1,N-1,l,-1,val); //cout << val << endl;
if(e[r].size()) val = *e[r].rbegin(); else val = -2;
upd(1,1,N-1,r,val,-1); //cout << val << endl;
if(L.size() == 0){
cout << 0 << endl;
continue;
}
int x = *L.rbegin();
int y = *R.begin();
if(x < y){
cout << (*b[x].begin() - *e[y].rbegin()) << endl;
} else {
//cout << "second : ";
cout << tree[1].answer << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
224 ms |
224120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
224 ms |
224120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
224 ms |
224120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
899 ms |
154600 KB |
Output is correct |
2 |
Correct |
904 ms |
154492 KB |
Output is correct |
3 |
Correct |
1698 ms |
190200 KB |
Output is correct |
4 |
Correct |
1713 ms |
190200 KB |
Output is correct |
5 |
Runtime error |
2112 ms |
410960 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
224 ms |
224120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |