#include #include #include #include #include #include #define MAX 1000100 #define LC(x) ((x) << 1) #define RC(x) (((x) << 1) | 1) #define AVG(x, y) (((x) & (y)) + (((x) ^ (y)) >> 1)) #define PAR int x, int l, int r #define LL LC(x), l, mid #define RR RC(x), mid + 1, r using namespace std; struct SegTree { int val, sum; } st[MAX << 2]; void pushUp(int x) { st[x].val = st[LC(x)].val == st[RC(x)].val ? st[LC(x)].val : -1; st[x].sum = st[LC(x)].sum + st[RC(x)].sum; } void pushDown(int x, int w) { if (~st[x].val) { st[LC(x)].val = st[RC(x)].val = st[x].val; st[LC(x)].sum = st[x].val * (w - (w >> 1)); st[RC(x)].sum = st[x].val * (w >> 1); } } void build(PAR) { int mid = AVG(l, r); if (l == r) { st[x].val = st[x].sum = 0; return; } build(LL); build(RR); pushUp(x); } void update(PAR, int low, int high, int val) { int mid = AVG(l, r); if (low <= l && r <= high) { st[x].val = val; st[x].sum = val * (r - l + 1); return; } pushDown(x, r - l + 1); if (low <= mid) update(LL, low, high, val); if (high > mid) update(RR, low, high, val); pushUp(x); } int query(PAR, int low, int high) { int mid = AVG(l, r), ret = 0; if (low <= l && r <= high) return st[x].sum; pushDown(x, r - l + 1); if (low <= mid) ret += query(LL, low, high); if (high > mid) ret += query(RR, low, high); return ret; } #define L 32 #define X first #define Y second typedef pair Pii; char cmd[MAX][8], buf[MAX][L]; string str[MAX]; inline string MakeLast(const char* str) { string ret(str); ret.push_back('z' + 1); return ret; } int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i < n; ++i) { scanf("%s%s", cmd[i], buf[i]); str[i] = string(buf[i]); } sort(str, str + n); int m = unique(str, str + n) - str; build(1, 0, m - 1); for (int i = 0; i < n; ++i) { if (cmd[i][0] == 'i') { int p = lower_bound(str, str + m, string(buf[i])) - str; int cur = query(1, 0, m - 1, p, p); update(1, 0, m - 1, p, p, cur + 1); } else if (cmd[i][0] == 'd') { int l = lower_bound(str, str + m, string(buf[i])) - str; int r = lower_bound(str, str + m, MakeLast(buf[i])) - str - 1; update(1, 0, m - 1, l, r, 0); } else if (cmd[i][0] == 's') { int l = lower_bound(str, str + m, string(buf[i])) - str; int r = lower_bound(str, str + m, MakeLast(buf[i])) - str - 1; int cur = query(1, 0, m - 1, l, r); printf("%s\n", cur ? "Yes" : "No"); } } } return 0; }