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