Codeforces 635D Factory Repairs "tree-like array"

Source: Internet
Author: User

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, &AMP;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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.