SPOJ GSS4 Can you answer these queries IV
来源:互联网 发布:如何练好字 知乎 编辑:程序博客网 时间:2024/06/06 00:46
题意:
给定一个序列和m个操作,
1,让l~r区间内的数都开方
2,求区间和。
思路:
由于LL内的数最多开方10次就会变成1了, 所以用区间维护区间和, 然后开方的时候如果不是全都是1的话就暴力开方, 区间内全都是1的话就不更新。
这么搞不是很靠谱的感觉。。用线段树套平衡树可以做到mlognlogn。。 但是懒得写了。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;#define LL long long#define N 100020#define ls (i << 1)#define rs (ls | 1)#define md ((ll + rr) >> 1)#define lson ll, md, ls#define rson md + 1, rr, rsint n;LL sum[N*4];void push_up(int i) {sum[i] = sum[ls] + sum[rs];}void build(int ll, int rr, int i) {if(ll == rr) {scanf("%lld", &sum[i]);return;}build(ll, md, ls);build(md + 1, rr, rs);push_up(i);}void update(int l, int r, int ll, int rr, int i) {if(sum[i] == rr - ll + 1)return;if(ll == rr) {sum[i] = sqrt(sum[i] + 0.5);return;}if(r <= md) update(l, r, lson);else if(l > md) update(l, r, rson);elseupdate(l, md, lson), update(md + 1, r, rson);push_up(i);}LL query(int l, int r, int ll, int rr, int i) {if(ll == l && rr == r) return sum[i];if(r <= md) return query(l, r, lson);if(l > md) return query(l, r, rson);return query(l, md, lson) + query(md + 1, r, rson);}int main() {int kk = 0;while(scanf("%d", &n) != EOF) {build(1, n, 1);int m;scanf("%d", &m);printf("Case #%d:\n", ++kk);while(m--) {int op, l, r;scanf("%d%d%d", &op, &l, &r);if(l > r) swap(l, r);if(op == 0)update(l, r, 1, n, 1);elseprintf("%lld\n", query(l, r, 1, n, 1));}puts("");}return 0;}
0 0
- SPOJ GSS4 Can you answer these queries IV
- SPOJ GSS4 Can you answer these queries IV (线段树)
- spoj GSS4 - Can you answer these queries IV 线段树
- SPOJ GSS4 Can you answer these queries IV
- GSS4 - Can you answer these queries IV
- SPOJ 2713. Can you answer these queries IV(GSS4 线段树)
- SPOJ 2713. Can you answer these queries IV(GSS4 线段树)
- [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】Can you answer these queries IV【线段树】
- 【线段树】 SPOJ 2713 Can you answer these queries IV
- SPOJ Can you answer these queries V
- Spoj 2713 Can you answer these queries IV 水线段树
- SPOJ 2713 Can you answer these queries IV(线段树)
- spoj SPOJ 1043 Can you answer these queries I
- Can you answer these queries IV(线段树区间和)
- SPOJ/GSS3:Can you answer these queries III(线段树)
- loadrunner异常处理:fopen is not allowed
- C语言面向对象编程(一):封装与继承
- NYOJ304(区间DP)
- 正则表达式30分钟入门教程
- Oracle 使用MERGE INTO 语句更新数据
- SPOJ GSS4 Can you answer these queries IV
- function toCamelCase( )
- 手机电池状态(0921)
- 在IOS后台执行
- IBM红宝书下载网站
- 程序设计C 实验三 题目二 距阵相乘(0074)
- PAT BASIC PRACTICE: 1008. 数组元素循环右移问题 (20)
- Linux用户基础
- Python爬虫Csdn系列I