可惜没如果=_=
时光的河入海流

3211: 花神游历各国

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 4017  Solved: 1465
[Submit][Status][Discuss]

Description

 

 

Input

 

 

Output

每次x=1时,每行一个整数,表示这次旅行的开心度

 

Sample Input

4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output

101

11

11

HINT

 

对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9


 

 

Source

妈了个鸡……一开始想了半天怎么打lazy怎么区间修改……然后猛然发现这明明是单点修改嘛……mdzz
线段树一种很神的操作,因为int范围内的数顶多开五次根号就成1了,以后再怎么开根号就都是1,所以开一个flag记录这段区间内是不是所有的数都为1了,如果都为1就不用再傻乎乎的更新一些不用更新的东西了qwq
laj颓了一个早上……mdzz这才是laj今天的T1
 1 #include "bits/stdc++.h"
 2 #define lson rt<<1,l,m
 3 #define rson rt<<1|1,m+1,r
 4 using namespace std;
 5 typedef long long LL;
 6 const int MAX=1e5+5;
 7 LL n,m;
 8 LL sum[MAX<<2],flag[MAX<<2];
 9 inline LL read(){
10     int an=0,x=1;char c=getchar();
11     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
12     while (c>='0' && c<='9') {an=(an<<3)+(an<<1)+c-'0';c=getchar();}
13     return an*x;
14 }
15 void PushUp(int rt){
16     sum[rt]=sum[rt<<1]+sum[rt<<1|1];
17     flag[rt]=flag[rt<<1]&flag[rt<<1|1];
18 }
19 void build(int rt,int l,int r){
20     if (l==r){
21         sum[rt]=read();
22         if (sum[rt]<=1) flag[rt]=1;
23         else flag[rt]=0;
24         return;
25     }
26     int m=(l+r)>>1;
27     build(lson);
28     build(rson);
29     PushUp(rt);
30 }
31 void update(int rt,int l,int r,int x,int y){
32     if (flag[rt]) return;
33     if (l==r){
34         sum[rt]=(LL)sqrt(sum[rt]*1.0);
35         if (sum[rt]<=1) flag[rt]=1;
36         return;
37     }
38     int m=(l+r)>>1;
39     if (x<=m) update(lson,x,y);
40     if (y>m) update(rson,x,y);
41     PushUp(rt);
42 }
43 LL query(int rt,int l,int r,int x,int y){
44     if (x<=l && r<=y) return sum[rt];
45     LL tmp=0;
46     int m=(l+r)>>1;
47     if (x<=m) tmp+=query(lson,x,y);
48     if (y>m) tmp+=query(rson,x,y);
49     return tmp;
50 }
51 int main(){
52     freopen ("flower.in","r",stdin);freopen ("flower.out","w",stdout);
53     int i,j,x,y,z;
54     n=read();build(1,1,n);
55     m=read();
56     for (i=1;i<=m;i++){
57         z=read(),x=read(),y=read();
58         if (z==1) printf("%lld\n",query(1,1,n,x,y));
59         else update(1,1,n,x,y);
60     }
61     return 0;
62 }

 

posted on 2017-10-28 12:48  珍珠鸟  阅读(335)  评论(0编辑  收藏  举报