WA 0pts
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
struct node{
int l,r;
int key,val;
int cnt,siz;
}a[100010],b[100010];
int idx,root,root1;
map<int,pair<pair<int,int>,int>> mp;
void push_up(int x)
{
a[x].siz=a[a[x].l].siz+a[a[x].r].siz+a[x].cnt;
}
int get_node(int x)
{
idx++;
a[idx].cnt=a[idx].siz=1;
a[idx].val=rand();
a[idx].key=x;
return idx;
}
void zag(int &p)
{
int q=a[p].r;
a[p].r=a[q].l;
a[q].l=p;
p=q;
push_up(a[p].l);
push_up(p);
}
void zig(int &p)
{
int q=a[p].l;
a[p].l=a[q].r;
a[q].r=p;
p=q;
push_up(a[p].r);
push_up(p);
}
void bulid()
{
get_node(-1e8);
get_node(1e8);
a[1].r=2;
root=1;
push_up(root);
if(a[1].val<a[2].val)
{
zag(root);
}
}
void insert(int &p,int key)
{
if(!p)
{
p=get_node(key);
}
else if(a[p].key == key)
{
a[p].cnt++;
}
else if(a[p].key>key)
{
insert(a[p].l,key);
if(a[a[p].l].val>a[p].val)
{
zig(p);
}
}
else
{
insert(a[p].r,key);
if(a[a[p].r].val>a[p].val)
{
zag(p);
}
}
push_up(p);
}
void erase(int &p,int key)
{
if(!p)
{
return ;
}
if(a[p].key == key)
{
if(a[p].cnt>1)
{
a[p].cnt--;
}
else if(a[p].l||a[p].r)
{
if(!a[p].r||a[a[p].l].val>a[a[p].r].val)
{
zig(p);
erase(a[p].r,key);
}
else
{
zag(p);
erase(a[p].l,key);
}
}
else
{
p = 0;
}
}
else if(key>a[p].key)
{
erase(a[p].r,key);
}
else
{
erase(a[p].l,key);
}
push_up(p);
}
int qp(int p,int key)
{
if(!p)
{
return 0;
}
if(key == a[p].key)
{
return a[a[p].l].siz+1;
}
if(a[p].key>key)
{
return qp(a[p].l,key);
}
return a[a[p].l].siz+a[p].cnt+qp(a[p].r,key);
}
int idx1;
void push_up1(int x)
{
b[x].siz=b[b[x].l].siz+b[b[x].r].siz+b[x].cnt;
}
int get_node1(int x)
{
idx1++;
b[idx1].cnt=b[idx1].siz=1;
b[idx1].val=rand();
b[idx1].key=x;
return idx1;
}
void zag1(int &p)
{
int q=b[p].r;
b[p].r=b[q].l;
b[q].l=p;
p=q;
push_up1(b[p].l);
push_up1(p);
}
void zig1(int &p)
{
int q=b[p].l;
b[p].l=b[q].r;
b[q].r=p;
p=q;
push_up1(b[p].r);
push_up1(p);
}
void bulid1()
{
get_node1(-1e8);
get_node1(1e8);
b[1].r=2;
root1=1;
push_up1(root1);
if(b[1].val<b[2].val)
{
zag1(root1);
}
}
void insert1(int &p,int key)
{
if(!p)
{
p=get_node1(key);
}
else if(b[p].key == key)
{
b[p].cnt++;
}
else if(b[p].key>key)
{
insert1(b[p].l,key);
if(b[b[p].l].val>b[p].val)
{
zig1(p);
}
}
else
{
insert1(b[p].r,key);
if(b[b[p].r].val>b[p].val)
{
zag1(p);
}
}
push_up1(p);
}
void erase1(int &p,int key)
{
if(!p)
{
return ;
}
if(b[p].key == key)
{
if(b[p].cnt>1)
{
b[p].cnt--;
}
else if(b[p].l||b[p].r)
{
if(!b[p].r||b[b[p].l].val>b[b[p].r].val)
{
zig1(p);
erase1(b[p].r,key);
}
else
{
zag1(p);
erase1(b[p].l,key);
}
}
else
{
p = 0;
}
}
else if(key>b[p].key)
{
erase1(b[p].r,key);
}
else
{
erase1(b[p].l,key);
}
push_up1(p);
}
int qp1(int p,int key)
{
if(!p)
{
return 0;
}
if(key == b[p].key)
{
return b[b[p].r].siz+1;
}
if(b[p].key<key)
{
return qp1(b[p].r,key);
}
return b[b[p].r].siz+b[p].cnt+qp1(b[p].l,key);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("P5482_1.in.txt","r",stdin);
// bulid();
// bulid1();
cin>>n;
int cnt=0,idxx=0;
for(int i=1;i<=n;i++)
{
string s;
int x,y,z;
cin>>s;
if(s[0]=='A')
{
cin>>x>>y>>z;
if(x == 0)
{
cnt+=(y>z);
}
else
{
if(x>0)
{
int xx=floor(1.0*(1.0*(z-y))/x);
xx+=1;
// cout<<xx<<'\n';
insert(root,xx);
}
else
{
int xx=ceil(1.0*(1.0*(z-y))/x);
// cout<<xx<<'\n';
xx-=1;
// cout<<xx<<'\n';
insert1(root1,xx);
}
}
idxx++;
mp[idxx]={{x,y},z};
}
if(s[0]=='Q')
{
int k;
cin>>k;
// cout<<qp(root,k)<<' '<<qp1(root1,k)<<' '<<cnt<<'\n';
cout<<qp(root,k)+qp1(root1,k)+cnt<<'\n';
}
if(s[0]=='D')
{
int pos;
cin>>pos;
int x=mp[pos].first.first;
int y=mp[pos].first.second;
int z=mp[pos].second;
if(x == 0)
{
cnt-=(y>z);
}
else
{
if(x>0)
{
int xx=floor(1.0*(1.0*(z-y))/x);
xx+=1;
erase(root,xx);
}
else
{
int xx=ceil(1.0*(1.0*(z-y))/x);
xx-=1;
erase1(root1,xx);
}
}
}
}
return 0;
}