B. Factory repairs--cf627b (segment tree)

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/627/B

The main topic: N for the number of days, K for each maintenance of the duration of the day, a for the maintenance after the daily production of a product, b for maintenance before the daily production of only B products Q for Q times query

Each query will enter a number first

1, D-Day received a order

2, starting from the first day of maintenance of these days (the next K days do not work in the first day before the production of B products, p+k days after the maintenance, so every day after the production of a product)

I have not read the topic at the beginning, and then on the CF looked at it there is a hint and then the line tree

I think my method is rather stupid I put every >a | | The >b are saved with a variable, and I have saved no more than a and not less than B and

The last update point is on the line.

I just started writing, ignoring if he adds a number if it's bigger than a, his and should subtract his own value.

#include <stdio.h>#include<stdlib.h>#include<algorithm>#include<math.h>#include<string.h>#include<iostream>#include<queue>#include<ctype.h>using namespacestd;#defineN 200005#defineMet (A, a) memset (a,b,sizeof (b))#defineLson r<<1|1#defineRson r<<1intn,k,x,y;structnode{intl,r,e; Long Long intLsum,rsum,ls,rs; intmid () {return(L+R)/2; }}a[n*4];voidBuildtree (intRintLintR) {A[r]. L=m; A[R]. R=s; A[R].E=0; A[R]. Lsum=0; A[R]. Rsum=0; A[R]. Ls=0; A[R]. Rs=0; if(l==R)return;    Buildtree (Lson,l,a[r].mid ()); Buildtree (Rson,a[r].mid ()+1, R); A[R]. Lsum=a[lson]. lsum+A[rson].    Lsum; A[R]. Rsum=a[lson]. rsum+A[rson].    Rsum; A[R]. Ls=a[lson]. ls+A[rson].    Ls; A[R]. Rs=a[lson]. rs+A[rson]. Rs;}voidUpdate (intRintLintv) {    if(A[r]. L==A[R]. R && A[r]. l==L) {intkk=A[R].E; A[R].E+=v; if(A[r].e>=y && kk<y) {a[r]. Lsum++; A[R]. Ls-=KK; }        if(A[r].e>=x && kk<x) {A[r]. Rs-=KK; A[R]. Rsum++; }        if(a[r].e<y) a[r]. Ls=A[R].E; if(a[r].e<x) a[r]. Rs=A[R].E; return; }    if(l>A[r].mid ())    Update (RSON,L,V); ElseUpdate (LSON,L,V); A[R]. Lsum=a[lson]. lsum+A[rson].    Lsum; A[R]. Rsum=a[lson]. rsum+A[rson].    Rsum; A[R]. Ls=a[lson]. ls+A[rson].    Ls; A[R]. Rs=a[lson]. rs+A[rson]. Rs;}Long Long intQurry (intRintLintRintb) {    if(l>R)return 0; if(A[r]. L==l && A[r]. r==R) {if(b==1)            returnA[R]. lsum*y+A[r].        Ls; Else if(b==2)            returnA[R]. rsum*x+A[r].    Rs; }    if(l>A[r].mid ())returnQurry (RSON,L,R,B); Else if(r<=A[r].mid ())returnQurry (LSON,L,R,B); Else    {        Long Longa1=Qurry (Lson,l,a[r].mid (), b); Long LongA2=qurry (Rson,a[r].mid () +1, r,b); returna1+A2; }}intMain () {intQ;  while(SCANF ("%d", &n)! =EOF) {Met (A,0); intu,v; Buildtree (1,1, N); scanf ("%d %d%d%d",&k,&x,&y,&q);  while(q--)        {            intKK; scanf ("%d",&KK); if(kk==1) {scanf ("%d%d",&u,&W); Update (1, u,v); }            Else{scanf ("%d",&u); Long Long intSum1=qurry (1,1, U-1,1); Long Long intSum2=qurry (1, U+k,n,2); printf ("%lld\n", sum1+sum2); }        }    }    return 0;}

B. Factory repairs--cf627b (segment tree)

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.