BZOJ3211 the world of flowers and Gods

Source: Internet
Author: User

Description Input Output

Each time x=1, an integer per line indicates the pleasure of this trip

Sample Input4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output101

11

11

HINT

For 100% data, n≤100000,m≤200000, Data[i] is non-negative and less than 10^9

Each number of logs (Logai) is changed to 0 or 1, so it is possible to modify a single point per brute force. But how do we find all the points in the interval that are not 0 and 1? Use and check to maintain the next valid location for each location, see the code for details.
#include <cstdio>#include<cstring>#include<algorithm>#include<cctype>#include<cmath>#defineRep (s,t) for (int i=s;i<=t;i++)#defineren for (int i=first[x];i!=-1;i=next[i])using namespaceStd;typedefLong Longll;inline ll Read () {ll x=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn=100010;intN,fa[maxn],a[maxn];inlineintFindset (intx) {return!fa[x]| | x==fa[x]?x:fa[x]=Findset (fa[x]);} ll C[MAXN];voidAddintX,ll v) { for(; x<=n;x+=x&-x) c[x]+=v;} ll sum (intx) {ll ret=0; for(; x;x-=x&-x) ret+=c[x];returnret;}intMain () {n=read (); Rep (1, N) {Add (I,a[i]=read ()); if(a[i]<=1) fa[i]=i+1; }    intq=read ();  while(q--) {        intT=read (), L=read (), r=read (); if(t==1) printf ("%lld\n", SUM (R)-sum (l1)); Else {             for(intI=findset (l); I<=r;i=findset (i+1)) {                intt=sqrt (a[i]); Add (i,t-a[i]); a[i]=T; if(a[i]<=1) Fa[i]=findset (i+1); }        }    }    return 0;}
View Code

BZOJ3211 the world of flowers and Gods

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.