It's been a long time to see the topic ...
Topic Links:
Http://codeforces.com/contest/635/problem/D
Test instructions
A factory production repair before the daily production of B, repair K days after the production of a every day, maintenance is not produced.
Several operations:
1.1 d AA D days require AA orders, an order corresponding to an item, must be completed on this day.
2.2 d start maintenance, and how many orders can be received at the end of the day.
Analysis:
The tree array maintains the number of orders received before and after maintenance, so that the two additions can be made for different repair dates.
Code:
#include <cstdio>#include <iostream>#include <cstring>using namespace STD;#define PR (x) cout << #x << ":" << x << ""#define PL (x) cout << #x << ":" << x << Endl;#define SA (x) scanf ("%d",& (x) )#define MDZZ cout<< "Mdzz" <<endl;Const intMAXN =2e5+5, oo =0x3f3f3f3f;typedef Long LongllintBITA[MAXN], BITB[MAXN], CNT[MAXN];//a after repair B before repairintNintSumainti) {intAns =0; while(i) {ans + = bita[i]; I-= i &-i; }returnAns;}intSumb (inti) {intAns =0; while(i) {ans + = bitb[i]; I-= i &-i; }returnAns;}voidAddaintIintx) { while(I <= N) {Bita[i] + = x; i + = i &-i; }}voidADDB (intIintx) { while(I <= N) {Bitb[i] + = x; i + = i &-i; }}intMain (void){intK, A, B, Q;sa (n); SA (k); SA (a); SA (b); SA (q);intAA, D;intAns =0; for(inti =0; i < Q; i++) {intType;sa (type);if(Type = =1){scanf("%d%d", &d, &AA); Adda (d,-min (Cnt[d], a)); Addb (d,-min (Cnt[d], b));//RecoveryCNT[D] + = AA; Adda (d, Min (Cnt[d], a)); Addb (d, Min (Cnt[d], b)); }Else{SA (d); Ans + = Sumb (D-1) + suma (n)-Suma (d + K-1);printf("%d\n", ans); Ans =0; } }return 0;}
Codeforces 635D Factory Repairs "tree-like array"