关闭

HDU 4027 Can you answer these queries? 线段树

标签: acm
238人阅读 评论(0) 收藏 举报
分类:

题意:

给你一个区间

有两种操作 i)把x~y区间数据减小至原来的值的平方根 ii)查询区间x~y的值

分析:

简单的线段树更新,强烈剪枝  如果区间和sum【st】=r-l+1说明这个区间值全为一不需要继续操作 tle->ac

ACcode:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define maxn 100002
#define ll long long
#define inf 0x3f3f3f3f
#define mid ((l+r)>>1)
#define tmp (st<<1)
#define len (r-l+1)
#define lson l,mid,tmp
#define rson mid+1,r,tmp|1
#define push_up(x) sum[x]=sum[tmp]+sum[tmp|1]
using namespace std;
ll sum[maxn<<2];
inline void build(int l,int r,int st){
    sum[st]=0;
    if(l==r){
        scanf("%I64d",&sum[st]);
        return ;
    }
    build(lson);
    build(rson);
    push_up(st);
}
inline void updata(int L,int R,int l,int r,int st){
    if(sum[st]==r-l+1)return;
    if(l==r){
        sum[st]=sqrt(double(sum[st]));
        return ;
    }
    if(L<=mid)updata(L,R,lson);
    if(R>mid)updata(L,R,rson);
    push_up(st);
}
inline ll query(int L,int R,int l,int r,int st){
    if(L<=l&&r<=R)return sum[st];
    ll ret=0;
    if(L<=mid)ret+=query(L,R,lson);
    if(R>mid)ret+=query(L,R,rson);
    return ret;
}
int main(){
    int cnt=1,n,q;
    while(~scanf("%d",&n)){
        build(1,n,1);
        scanf("%d",&q);
        printf("Case #%d:\n",cnt++);
        while(q--){
            int k,x,y;
            scanf("%d%d%d",&k,&x,&y);
            if(x>y)x^=y^=x^=y;
            if(k)printf("%I64d\n",query(x,y,1,n,1));
            else updata(x,y,1,n,1);
        }
        putchar('\n');
    }
    return 0;
}


0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

H - Can you answer these queries? HDU 4027 (线段树+延迟标记+开根号的速度)

H - Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I...
  • u013167299
  • u013167299
  • 2015-04-06 21:29
  • 342

hdu 4027 Can you answer these queries?(线段树)(单点更新 但需要标记记录剪枝)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目大意:给定100000个数,两种操作,0 i j表示将i j这段的数字都开根号(向下取整)...
  • qq_36782366
  • qq_36782366
  • 2017-07-14 23:00
  • 39

【线段树区间单点更新加约束条件】HDU - 4027 Can you answer these queries?

Problem Description 给你一个n,接下来有n个数,给你m个操作,操作分为0的时候对区间L,R内的所有元素开根号,1的时候求区间L,R所有元素的和 思路:因为最大的数2的63次方,...
  • bbbbswbq
  • bbbbswbq
  • 2017-07-25 09:28
  • 72

HDU 4027 Can you answer these queries?【线段树】区间开平方,区间求和

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
  • liuke19950717
  • liuke19950717
  • 2015-11-21 19:50
  • 197

HDU 4027 Can you answer these queries?(线段树、查询区间和及修改区间数为数的平方根)

题目链接: HDU 4027 Can you answer these queries? 分析: longlong longlong范围内每个数最多开8次方就会变为1,当当前区间所有数都变为1...
  • Ramay7
  • Ramay7
  • 2016-04-29 01:16
  • 255

hdu 4027 Can you answer these queries?(线段树——区间更新)(思路)

Can you answer these queries?Problem Description A lot of battleships of evil are arranged in a lin...
  • blessLZH0108
  • blessLZH0108
  • 2017-04-24 21:51
  • 279

hdu4027——Can you answer these queries?(线段树+区间更新变形)

Problem Description A lot of battleships of evil are arranged in a line before the battle. Our comm...
  • blue_skyrim
  • blue_skyrim
  • 2016-09-16 19:12
  • 576

hdoj 4027 Can you answer these queries? 【线段树 区间减为平方 + 区间求和】

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...
  • chenzhenyu123456
  • chenzhenyu123456
  • 2015-10-11 20:17
  • 402

HDOJ 题目4027 Can you answer these queries?(线段树,区间减为平方根,区间求和)

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K...
  • yu_ch_sh
  • yu_ch_sh
  • 2015-07-30 16:09
  • 460

T - Can you answer these queries?(单点更新,线段树优化)

http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=216#problem/T 对n个整数有m个操作,共有两种操作:0 l ...
  • u013081425
  • u013081425
  • 2014-08-16 19:53
  • 658
    个人资料
    • 访问:376953次
    • 积分:11812
    • 等级:
    • 排名:第1476名
    • 原创:805篇
    • 转载:2篇
    • 译文:0篇
    • 评论:111条
    最新评论