1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 using namespace std; 7 8 const int MAXN = 20010; 9 const int MAXT = MAXN << 2; 10 const int MAXP = 55; 11 12 struct Node { 13 int pos, op, time; 14 Node() {} 15 Node(int pos, int op, int time): pos(pos), op(op), time(time) {} 16 bool operator < (const Node &rhs) const { 17 return pos < rhs.pos; 18 } 19 }; 20 21 vector<int> qtime[MAXN], qid[MAXN]; 22 Node attack[MAXN * 2]; 23 int ans[MAXN]; 24 int T, n, q, t, ncnt, atime; 25 26 void init() { 27 for(int i = 0; i <= n; ++i) qtime[i].clear(), qid[i].clear(); 28 memset(ans, -1, q * sizeof(int)); 29 ncnt = atime = 0; 30 } 31 32 #define ll (x << 1) 33 #define rr (ll | 1) 34 #define mid ((l + r) >> 1) 35 int atk[MAXT][MAXP], empty[MAXT][MAXP]; 36 int cnt[MAXN]; 37 38 void update(int x) { 39 for(int i = 0; i < t; ++i) { 40 int t = empty[ll][i]; 41 atk[x][i] = atk[ll][i] + atk[rr][t]; 42 empty[x][i] = empty[rr][t]; 43 } 44 } 45 46 void build(int x, int l, int r) { 47 if(l == r) { 48 atk[x][0] = empty[x][0] = cnt[l] = 0; 49 for(int i = 1; i < t; ++i) 50 atk[x][i] = 0, empty[x][i] = i - 1; 51 } else { 52 build(ll, l, mid); 53 build(rr, mid + 1, r); 54 update(x); 55 } 56 } 57 58 void modify(int x, int l, int r, int a, int b) { 59 if(a <= l && r <= b) { 60 atk[x][0] = 0; empty[x][0] = cnt[a] ? t - 1 : 0; 61 for(int i = 1; i < t; ++i) 62 atk[x][i] = cnt[a], empty[x][i] = i - 1; 63 } else { 64 if(a <= mid) modify(ll, l, mid, a, b); 65 if(mid < b) modify(rr, mid + 1, r, a, b); 66 update(x); 67 } 68 } 69 70 void modify(int pos) { 71 modify(1, 1, atime, pos, pos); 72 } 73 74 int query(int x, int l, int r, int a, int b, int e) { 75 if(a <= l && r <= b) { 76 return atk[x][e]; 77 } else { 78 int res = query(ll, l, mid, a, b, e); 79 if(mid < b) res += query(rr, mid + 1, r, a, b, empty[ll][e]); 80 return res; 81 } 82 } 83 84 int query(int pos) { 85 if(pos == 0) return 0; 86 return query(1, 1, atime, 1, pos, 0); 87 } 88 89 char s[10]; 90 91 int main() { 92 scanf("%d", &T); 93 for(int kase = 1; kase <= T; ++kase) { 94 scanf("%d%d%d", &n, &q, &t); 95 init(); 96 for(int i = 0, a, b; i < q; ++i) { 97 scanf("%s", s); 98 if(strcmp(s, "Attack") == 0) { 99 scanf("%d%d", &a, &b); 100 atime++; 101 attack[ncnt++] = Node(a, 1, atime); 102 attack[ncnt++] = Node(b + 1, -1, atime); 103 } else { 104 scanf("%d", &a); 105 qtime[a].push_back(atime); 106 qid[a].push_back(i); 107 } 108 } 109 sort(attack, attack + ncnt); 110 111 build(1, 1, atime); 112 int p = 0; 113 for(int i = 1; i <= n; ++i) { 114 while(p < ncnt && attack[p].pos == i) { 115 cnt[attack[p].time] += attack[p].op; 116 modify(attack[p++].time); 117 } 118 for(size_t k = 0; k < qtime[i].size(); ++k) 119 ans[qid[i][k]] = query(qtime[i][k]); 120 } 121 122 printf("Case %d:\n", kase); 123 for(int i = 0; i < q; ++i) 124 if(ans[i] != -1) printf("%d\n", ans[i]); 125 } 126 }