zoukankan      html  css  js  c++  java
  • BZOJ-3211: 花神游历各国 (线段树)

    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
    ",query(1,1,n,x,y));
    59         else update(1,1,n,x,y);
    60     }
    61     return 0;
    62 }
    未来是什么样,未来会发生什么,谁也不知道。 但是我知道, 起码从今天开始努力, 肯定比从明天开始努力, 要快一天实现梦想。 千里之行,始于足下! ——《那年那兔那些事儿》
  • 相关阅读:
    centos“You don't have permission to access /index.html on this server.”
    使用yum来安装或卸载CentOS图形界面包
    PHP上IIS上显示服务器应用程序不可用
    Windows 2003 远程桌面连接数超过最大连接数终极解决方案
    perl清理电脑上重复的文件
    wordpress在IIS6上首页访问不了
    WordPress首页出现循环重定向解决办法四则(转载)
    windows server 2003 如何在远程链接时更改用户密码
    Ubuntu下安装php5gd库,支持jpg、png、gif等格式图片处理
    wordpress设置用163邮箱账号发送邮件
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7746514.html
Copyright © 2011-2022 走看看