【线段树】 SPOJ 2713 Can you answer these queries IV
来源:互联网 发布:知乎同类型网站 编辑:程序博客网 时间:2024/05/16 17:21
更新操作:一段区间内的全部数开根号
查询操作:一段区间内的sum值
在一个值更新操作十几次之后会变成 1 之后就不需要再更新这段了
所以在update 某个区间 r-l+1==sum[rt] j就return
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#define cler(arr, val) memset(arr, val, sizeof(arr))#define FOR(i,a,b) for(int i=a;i<=b;i++)#define IN freopen ("in.txt" , "r" , stdin);#define OUT freopen ("out.txt" , "w" , stdout);typedef long long LL;const int MAXN = 120000;const int MAXM = 200000;const int INF = 0x3f3f3f3f;const int mod = 1000000007;const double eps= 1e-8;#define lson l,m, rt<<1#define rson m+1,r,rt<<1|1LL sum[MAXN<<2];void pushup(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ if(l==r) { scanf("%lld",&sum[rt]); return ; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt);}LL query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R) return sum[rt]; int m=(l+r)>>1; LL res=0; if(L<=m) res+=query(L,R,lson); if(R>m) res+=query(L,R,rson); return res;}void update(int L,int R,int l,int r,int rt){ if(r-l+1==sum[rt]&&L<=l && r<=R) return ; if(l==r) { sum[rt]=(LL)sqrt(sum[rt]*1.0); return ; } int m=(l+r)>>1; if(L<=m) update(L,R,lson); if(R>m) update(L,R,rson); pushup(rt);}int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);#endif int m,n,cas=0,flag=0; while(scanf("%lld",&n)!=EOF) { build(1,n,1); scanf("%d",&m); printf("Case #%d:\n",++cas); for(int i=0;i<m;i++) { int ls,rs,op; scanf("%d%d%d",&op,&ls,&rs); if(rs<ls)swap(ls,rs); if(op) printf("%lld\n",query(ls,rs,1,n,1)); else update(ls,rs,1,n,1); } puts(""); } return 0;}
0 0
- 【线段树】 SPOJ 2713 Can you answer these queries IV
- spoj 2713. Can you answer these queries IV(线段树)
- SPOJ GSS4 Can you answer these queries IV (线段树)
- 【SPOJ】Can you answer these queries IV【线段树】
- spoj GSS4 - Can you answer these queries IV 线段树
- SPOJ 2713 Can you answer these queries IV(线段树)
- spoj 2713 Can you answer these queries IV
- SPOJ 2713. Can you answer these queries IV(GSS4 线段树)
- SPOJ 2713. Can you answer these queries IV(GSS4 线段树)
- Can you answer these queries IV(线段树区间和)
- SPOJ/GSS3:Can you answer these queries III(线段树)
- spoj 1043. Can you answer these queries I (线段树)
- spoj 1557. Can you answer these queries II(线段树)
- spoj 1716. Can you answer these queries III(线段树)
- spoj 2916. Can you answer these queries V(线段树)
- SPOJ GSS3 Can you answer these queries III (线段树)
- 【SPOJ】Can you answer these queries I【线段树】
- 【SPOJ】Can you answer these queries III【线段树】
- 黑马程序员-.NET基础之文件和I/O流
- 黑马程序员_File和Properties概述
- hdu_1540Tunnel Warfare
- b70u.biri1q.xyz
- 致自己——独自走
- 【线段树】 SPOJ 2713 Can you answer these queries IV
- 桶排序
- libevent逻辑处理图
- 队列的顺序存储
- eclipse中查看自己更改的代码跟svn中代码的比较
- 黑马程序员_IO中其他流对象
- <<不能承受的生命之轻>>
- datatable1.10服务器断分页
- 信管--小结篇