Line Tree/Violence
Segment Tree Interval root
Alas, I was a bit silly, the tle, because did not consider the situation of 0 ...
All right, let's just say, the segment tree dynamic query interval and everyone will do ... The trouble is that this change into a prescription, however, there is nothing good, notice that the weight of the range is $10^9$, we can easily hit a table to find that the $10^9$ constantly open the root of the result is: 1000000000,31622,177,13,3,1. That is, each number, it opened the root of the number of times there is not much (Lenovo CF 250 of the interval to take the model of the problem!) So we maintain an interval maximum, each time the violence on each number open root on it (if the interval maximum is 0 or 1 can be skipped)
1 /**************************************************************2 problem:32113 User:tunix4 language:c++5 result:accepted6 time:1276 Ms7 memory:6364 KB8 ****************************************************************/9 Ten //Bzoj 3211 One#include <vector> A#include <cmath> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; atInlineintGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=1e5+Ten, inf=~0u>>2; -typedefLong LongLL; to /******************tamplate*********************/ + - intn,m,a[n],mx[n<<2]; theLL sm[n<<2]; * #defineL (o<<1) $ #defineR (o<<1|1)Panax Notoginseng #defineMid (L+r>>1) - voidMaintain (into) { themx[o]=Max (Mx[l],mx[r]); +sm[o]=sm[l]+Sm[r]; A } the voidBuildintOintLintR) { + if(L==R) {mx[o]=sm[o]=a[l];} - Else{ $ build (L,l,mid); $Build (r,mid+1, R); - maintain (o); - } the } - voidUpdateintOintLintRintQlintqr) {Wuyi if(mx[o]==1|| mx[o]==0)return; the if(L==R) {mx[o]=sm[o]=sqrt (Mx[o]);} - Else{ Wu if(ql<=mid) Update (L,L,MID,QL,QR); - if(qr>mid) Update (r,mid+1, R,QL,QR); About maintain (o); $ } - } - LL ans; - voidQueryintOintLintRintQlintqr) { A if(ql<=l && qr>=r) ans+=Sm[o]; + Else{ the if(ql<=mid) query (L,L,MID,QL,QR); - if(qr>mid) query (r,mid+1, R,QL,QR); $ } the } the intMain () { the #ifndef Online_judge theFreopen ("3211.in","R", stdin); -Freopen ("3211.out","W", stdout); in #endif then=getint (); theF (I,1, N) a[i]=getint (); AboutBuild1,1, n); them=getint (); theF (I,1, M) { the intCmd=getint (), L=getint (), r=getint (); + if(cmd==1){ -ans=0; theQuery1,1, n,l,r);Bayiprintf"%lld\n", ans); the}ElseUpdate1,1, n,l,r); the } - return 0; -}
View Code 3211: The flower God travels the country time Limit:5 Sec Memory limit:128 MB
submit:1327 solved:511
[Submit] [Status] [Discuss] 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
Source
SPOJ2713 GSS4 data has been enhanced
[Submit] [Status] [Discuss]
"Bzoj" "3211" flower Gods travel around the world