Code:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7, MAX = 2e6 + 10;
#define pyl 1e6 + 10
int n, kt[MAXN], tp, ans, vis[MAXN], k[MAXN];
int c1[MAX+7], c2[MAX+7];
#define lb(i)(i & -i)
inline void modify(int x, int y, int c[]) {
for (x; x <= MAX; x += lb(x)) c[x] += y;
}
inline int query(int x, int c[]) {
int ans = 0;
for (; x; x -= lb(x)) ans += c[x];
return ans;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i ++) {
string s;
cin >> s;
if (s == "Add") {
int x, y, z;
cin >> x >> y >> z;
if (x == 0) {
if (y - z > 0) kt[++ tp] = 3, ans ++;
else kt[++ tp] = 0;
} else if (x < 0) {
k[++ tp] = ceil((z * 1.0 - y) / x) + pyl;
if (k[tp] > 1e6) kt[tp] = 3, ans ++;
else if (k[tp] < -1e6) kt[tp] = 0;
else kt[tp] = 1, modify(k[tp] + pyl, 1, c2);
} else if (x > 0) {
k[++ tp] = floor((z * 1.0 - y) / x) + pyl;
if (k[tp] > 1e6) kt[tp] = 0;
else if (k[tp] < -1e6) kt[tp] = 3, ans ++;
else kt[tp] = 2, modify(k[tp] + pyl, 1, c1);
}
} else if (s == "Del") {
int x;
cin >> x;
if (vis[x]) continue;
vis[x] = 1;
if (kt[x] == 3) ans --;
else if (kt[x] == 1) modify(k[x], -1, c2);
else if (kt[x] == 2) modify(k[x], -1, c1);
} else if (s == "Query") {
int x;
cin >> x;
cout << (query(x - 1 + pyl, c1) + (query(MAX, c2) - query(x + pyl, c2)) + ans) << "\n";
}
}
return 0;
}