hdu 4027 Can you answer these queries?
来源:互联网 发布:华硕驱动更新软件 编辑:程序博客网 时间:2024/05/16 16:50
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4027
线段树,区间开方求和。。
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#define lc root<<1#define rc root<<1|1#define mid ((l+r)>>1)typedef unsigned long long ull;const int Max_N = 100010;struct Node { ull val; bool flag; };struct SegTree { Node seg[Max_N << 2]; inline void push_up(int root) { seg[root].val = seg[lc].val + seg[rc].val; } inline void built(int root, int l, int r) { seg[root].flag = false; if (l == r) { scanf("%lld", &seg[root].val); return; } built(lc, l, mid); built(rc, mid + 1, r); push_up(root); } inline void update(int root, int l, int r, int x, int y) { if (x > r || y < l || seg[root].flag) return; if (l == r) { seg[root].val = (ull)sqrt((double)seg[root].val); if (1 == seg[root].val) seg[root].flag = true; return; } update(lc, l, mid, x, y); update(rc, mid + 1, r, x, y); push_up(root); seg[root].flag = seg[lc].flag && seg[rc].flag; } inline ull query(int root, int l, int r, int x, int y) { if (x > r || y < l) return 0; if (x <= l && y >= r) return seg[root].val; ull v1 = query(lc, l, mid, x, y); ull v2 = query(rc, mid + 1, r, x, y); return v1 + v2; }}seg;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout);#endif int n, q, a, b, c, k = 1; while (~scanf("%d", &n)) { seg.built(1, 1, n); scanf("%d", &q); printf("Case #%d:\n", k++); while (q--) { scanf("%d %d %d", &a, &b, &c); if (b > c) b ^= c ^= b ^= c; if (!a) seg.update(1, 1, n, b, c); else printf("%lld\n", seg.query(1, 1, n, b, c)); } printf("\n"); } return 0;}
0 0
- HDU--4027(Can you answer these queries?)
- HDU-4027-Can you answer these queries
- hdu 4027 Can you answer these queries?
- HDU-4027-Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- HDU--4027(Can you answer these queries?)
- hdu - 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- 读书笔记1、谁说菜鸟不会数据分析(入门篇)
- LTE
- HDU 3746 Cyclic Nacklace (KMP 循环节)
- SpringMVC中怎样从一个Controller方法跳转到另一个方法,注意是跳转,不是调用如题类
- [Objective-C] id、self、super
- hdu 4027 Can you answer these queries?
- 正则表达式-笔记
- fedora10 安装tftp服务
- Python之学习笔记(常用内建模块)
- LeetCode Course Schedule
- Android中Activity启动模式详解,可以控制程序按home键后进来还会调用一个自己不喜欢的界面
- hdu 1004 Let the Balloon Rise
- utf8 cat正常vi乱码
- 3.3OC视频笔记(respondsToSelect)3.4,3.5(字符串的创建与比较方法)(详解isEqualToString)(详解isEqual)