BZOJ3038 && BZOJ3211 上帝造题的七分钟2 && 花神游历各国 (线段树 + 开方标记)
来源:互联网 发布:java用户输入数组 编辑:程序博客网 时间:2024/04/26 05:27
传送门
这道题看一眼就知道是线段树的题目,但是一看,题目要求区间开方,我就又傻了。想了一会,发现就算是
代码:
#include <cstdio>#include <cmath>#define LL long longinline void swap(int &a, int &b) {int c = a; a = b; b = c;}#define MAXN 100005inline void GET(LL &n){ n = 0; char c; do c = getchar(); while(c > '9' || c < '0'); while(c <= '9' && c >= '0') {n = n * 10 + c - '0'; c = getchar();}}inline void GET(int &n){ n = 0; char c; do c = getchar(); while(c > '9' || c < '0'); while(c <= '9' && c >= '0') {n = n * 10 + c - '0'; c = getchar();}}struct node{ LL sum; bool lazy; node(){lazy = 0;}}t[MAXN<<1];inline int idx(int l, int r) {return (l + r) | (l != r);}void pushup(int l, int r){ int mid = (l + r) >> 1; t[idx(l, r)].sum = t[idx(l, mid)].sum + t[idx(mid+1, r)].sum; t[idx(l, r)].lazy = t[idx(l, mid)].lazy && t[idx(mid+1, r)].lazy;}void build(int l, int r){ int i = idx(l, r); if(l == r) { GET(t[i].sum); return; } int mid = (l + r) >> 1; build(l, mid); build(mid+1, r); t[idx(l, r)].sum = t[idx(l, mid)].sum + t[idx(mid+1, r)].sum;}int op, L, R, n, m;void Ins(int l, int r){ int i = idx(l, r); if(l > R || r < L) return; if(t[i].lazy) return; if(l == r) { t[i].sum = sqrt(t[i].sum); if(t[i].sum == 1 || t[i].sum == 0) t[i].lazy = 1; return; } int mid = (l + r) >> 1; Ins(l, mid); Ins(mid+1, r); pushup(l, r);}LL Sum(int l, int r){ if(l > R || r < L) return 0; if(l >= L && r <= R) return t[idx(l, r)].sum; int mid = (l+r)>>1; return Sum(l, mid) + Sum(mid+1, r);}int main(){ GET(n); build(1, n); GET(m); while(m --) { GET(op);GET(L);GET(R); if(op == 2) Ins(1, n); else if(op == 1) printf("%lld\n", Sum(1, n)); } return 0;}
0 0
- BZOJ3038 && BZOJ3211 上帝造题的七分钟2 && 花神游历各国 (线段树 + 开方标记)
- [BZOJ3211] 花神游历各国/[BZOJ3038] 上帝造题的七分钟2
- [BZOJ3211&3038][上帝造题的七分钟2&花神游历各国][线段树]
- codevs2492 上帝造题的七分钟2 BZOJ3211 花神游历各国
- bzoj3211: 花神游历各国&&3038: 上帝造题的七分钟2
- bzoj3038 上帝造题的七分钟2(线段树区间开方统计和)
- 【BZOJ】3211 花神游历各国 【CODE[VS]】2492 上帝造题的七分钟2 线段树
- [BZOJ3038][线段树]上帝造题的七分钟2
- 【bzoj3038】上帝造题的七分钟2 线段树
- 3038: 上帝造题的七分钟2/3211: 花神游历各国
- bzoj 3211: 花神游历各国 && bzoj 3038: 上帝造题的七分钟2
- BZOJ 3038 上帝造题的七分钟2 BZOJ 3211 花神游历各国 题解
- bzoj3211.花神游历各国(线段树)
- 花神游历各国 bzoj3211 线段树
- bzoj3211 花神游历各国 线段树
- [bzoj3211]花神游历各国 线段树
- bzoj3211 花神游历各国(线段树)
- bzoj3211花神游历各国 线段树
- hdu 4742 Pinball Game 3D(cdq分治+树状数组)
- Windows API函数大全
- struts入门案例
- 从xib创建完,往xib里添加东西的 2个方法
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)(A,B)
- BZOJ3038 && BZOJ3211 上帝造题的七分钟2 && 花神游历各国 (线段树 + 开方标记)
- The request sent by the client was syntactically incorrect问题解决
- python中两个整数相除得到浮点数的方法
- maven中 Could not create local repository问题原因及解决方法
- python连接,操作pgsql
- Java 操作集合的工具类:Collections
- Struts2学习(五)访问web元素总结
- 队列 c语言实现
- UIButton