题目链接
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2330 Accepted Submission(s): 695
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; const int maxn = 2e4+5; int sum[maxn<<2], add[maxn<<2]; void pushUp(int rt) { sum[rt] = sum[rt<<1]+sum[rt<<1|1]; } void pushDown(int rt, int m) { if(add[rt]) { sum[rt<<1] += (m-(m>>1))*add[rt]; sum[rt<<1|1] += (m>>1)*add[rt]; add[rt<<1] += add[rt]; add[rt<<1|1] += add[rt]; add[rt] = 0; } } void update(int L, int R, int l, int r, int rt) { if(L<=l&&R>=r) { sum[rt] += r-l+1; add[rt]++; return ; } pushDown(rt, r-l+1); int m = l+r>>1; if(L<=m) update(L, R, lson); if(R>m) update(L, R, rson); pushUp(rt); } int query(int p, int l, int r, int rt) { if(l == r) { return sum[rt]; } pushDown(rt, r-l+1); int m = l+r>>1; if(p<=m) return query(p, lson); else return query(p, rson); } int time[maxn], num[maxn]; pll att[maxn]; int main() { int t, n, q, k, x, y; cin>>t; char s[10]; for(int casee = 1; casee<=t; casee++) { printf("Case %d:\n", casee); mem(add); mem(num); mem(sum); mem(time); int cnt = 0; cin>>n>>q>>k; while(q--) { scanf("%s%d", s, &x); if(s[0] == 'A') { scanf("%d", &y); update(x, y, 1, n, 1); att[cnt++] = mk(x, y); } else { if(k == 1) { puts("0"); continue; } int tmp = query(x, 1, n, 1); for(int i = time[x]; i<cnt; i++) { if(x<=att[i].se&&x>=att[i].fi) { num[x]++; time[x] = i+k; i += k-1; } } printf("%d\n", tmp-num[x]); } } } return 0; }