CODEFORCES 438D The Child and Sequence <二叉树>
来源:互联网 发布:91苹果手机助手 mac版 编辑:程序博客网 时间:2024/05/16 00:37
传送门:http://codeforces.com/problemset/problem/438/D
题意:
给你一列n个数的数组,m个操作。
1、1 查询区间和
2、2 对区间每个数取mod
3、3 把某个数更改分析:算区间和,和最大值(优化操作,避免超时)
#include <cstdio>#include <iostream>using namespace std;#define LL long long#define max(x,y) (x>y?x:y)const int maxn = 100000+10;LL s[maxn<<2];int a[maxn<<2],ql,qr,q,qx;inline void updata(int t){ s[t] = s[t<<1] + s[t<<1|1]; a[t] = max(a[t<<1],a[t<<1|1]);}void build(int t,int l,int r){ if(l == r) { cin >> a[t]; s[t] = a[t]; return ; } int mid = (l+r)>>1; build(t<<1,l,mid); build(t<<1|1,mid+1,r); updata(t);}LL sum(int t,int l,int r){ if(ql<=l&&r<=qr) { return s[t]; } int mid = (l+r)>>1; LL ans =0; if(ql<=mid) ans+= sum(t<<1,l,mid); if(qr>mid) ans+=sum(t<<1|1,mid+1,r); return ans;}void mod(int t,int l,int r){ if(l==r) { a[t] %=qx; s[t] =a[t]; return ; } if(a[t] < qx) return ; int mid = (l+r)>>1; if(ql<=mid) mod(t<<1,l,mid); if(qr>mid) mod(t<<1|1,mid+1,r); updata(t);}void change(int t,int l,int r){ if(l==r) { a[t] = qx; s[t] = a[t]; return; } int mid = (l+r)>>1; if(q<=mid) change(t<<1,l,mid); else change(t<<1|1,mid+1,r); updata(t);}int main(){ int n,m,k; cin >> n >> m; build(1,1,n); while(m--) { cin >> k; // printf("m == %d k == %d\n",m,k); if(k == 1) { cin >> ql >> qr; printf("%lld\n",sum(1,1,n)); } else if(k == 2) { cin >> ql >> qr >> qx; mod(1,1,n); } else if(k == 3) { cin >> q >> qx; change(1,1,n); } } return 0;}
0 0
- CODEFORCES 438D The Child and Sequence <二叉树>
- CodeForces 438D The Child and Sequence
- 【Codeforces 438 D】The Child and Sequence
- [题解]codeforces 438d The Child and Sequence
- [均摊 平衡树 || 线段树] Codeforces 438D #250 (Div. 1) D. The Child and Sequence
- Codeforces Round #250 Div1D 438D The Child and Sequence 线段树+势能分析
- codeforces 438D The Child and Sequence(线段树:单点更新+区间取模+区间和)
- [均摊复杂度线段树]Codeforces 438D. The Child and Sequence
- [均摊复杂度线段树] Codeforces #438D. The Child and Sequence
- Codeforce 438D-The Child and Sequence
- CF(438D) The Child and Sequence(线段树)
- CF 438D The Child and Sequence [线段树]
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- CodeForces 438D The Child and Sequence 数据结构+点更新(赋值)+区间求和
- Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树暴力)
- 有趣的线段树小集合 Codeforces Round #250 (Div. 1) D. The Child and Sequence
- CF 438D The Child and Sequence(线段树取模)
- 线程同步——条件变量
- Zookeeper Api(java)入门与应用(转)
- 例题4-2 刽子手游戏 UVa489
- Eclipse上的重要功能提示
- C++在单继承、多继承、虚继承时,构造函数、复制构造函数、赋值操作符、析构函数的执行顺序和执行内容
- CODEFORCES 438D The Child and Sequence <二叉树>
- 使用POSIX Threads进行多线程编程(二) ——使用互斥量同步线程
- 判断二叉树是不是平衡
- Unity传统动画的实现
- substring with star
- hdu 5791 2016多校5
- 编写通用的java代码执行任意adb命令
- onmousedown事件---&&浏览器检测---&&脚本隐藏
- 逐步回归(step regression)和分段回归(stagewise regression)