上帝造题的7分钟2
来源:互联网 发布:房屋设计图平面图软件 编辑:程序博客网 时间:2024/04/30 07:38
题目>>http://codevs.cn/problem/2492/
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;const int MAXN = 2e5;typedef long long ll;struct zt{ ll l,r,sum,MAX; zt *lift,*right;}tree[MAXN];ll n,m,a,b,c,cnt = 0;void build(zt *root,ll l,ll r){ root->sum = 0;root->l = l;root->r = r;root->MAX = 0; if(l == r) return; root->lift = &tree[++cnt]; root->right = &tree[++cnt]; ll mid = l + r >>1; build(root->lift,l,mid); build(root->right,mid + 1,r);}void add(zt *root,ll l,ll r,ll q,ll x){ if(l == r) { root->sum += x; root->MAX += x; return; } ll mid = l + r>>1; if(q <= mid) add(root->lift,l,mid,q,x); else add(root->right,mid + 1,r,q,x); root->sum = root->lift->sum + root->right->sum; root->MAX = max(root->lift->MAX,root->right->MAX);}void sqr(zt *root,ll l,ll r,ll ql,ll qr){ if(root->MAX <= 1) return; if(l == r) { root->sum = sqrt(root->sum); root->MAX = sqrt(root->MAX); return; } ll mid = l + r>>1; if(ql <= mid) sqr(root->lift,l,mid,ql,qr); if(qr > mid) sqr(root->right,mid + 1,r,ql,qr); root->sum = root->lift->sum + root->right->sum; root->MAX = max(root->lift->MAX,root->right->MAX);}ll find(zt *root,ll l,ll r,ll ql,ll qr){ if(l >= ql&&qr >= r) return root->sum; ll mid = l + r>>1,ans = 0; if(ql <= mid) ans = find(root->lift,l,mid,ql,qr); if(qr > mid) ans += find(root->right,mid + 1,r,ql,qr); return ans;}int main(){ scanf("%lld",&n); build(tree,1,n); for(ll i = 1;i <= n;i ++) { scanf("%lld",&a); add(tree,1,n,i,a); } scanf("%lld",&m); for(int i = 1;i <= m;i ++) { scanf("%lld",&a); scanf("%lld%lld",&b,&c); if(b > c) swap(b,c); if(!a) sqr(tree,1,n,b,c); else cout<<find(tree,1,n,b,c)<<'\n'; }}
阅读全文
0 0
- 上帝造题的7分钟2
- bzoj3038 上帝造题7分钟2
- 【bzoj3038】 上帝造题的七分钟2
- [BZOJ3038][线段树]上帝造题的七分钟2
- bzoj3038 上帝造题的七分钟2
- BZOJ 3038: 上帝造题的七分钟2
- 【BZOJ3038】【Codevs2492】上帝造题的七分钟2
- BZOJ3038上帝造题的七分钟2
- [BZOJ3038]上帝造题的七分钟2
- codevs2492 上帝造题的七分钟 2
- bzoj 3038: 上帝造题的七分钟2
- 【bzoj3038】上帝造题的七分钟2
- BZOJ 3038 上帝造题的七分钟2
- 【codevs 2492】上帝造题的七分钟2
- bzoj 3038 上帝造题的七分钟2
- BZOJ 3038 上帝造题的七分钟2
- bzoj3038 上帝造题的七分钟2
- BZOJ 3038: 上帝造题的七分钟2
- java利用zxing生成二维码
- Qt中快捷键& 的使用方法
- HTML5-背景颜色图片-班级-展开收起-懒加载
- Distutils发布C++扩展的Python模块
- 使用Scikit-learn实现基于内存的协同过滤算法(使用movieLens数据集)
- 上帝造题的7分钟2
- centos7 安装mysql步骤
- idea 创建java web项目(maven管理的SSH)
- 字典树模板(数组实现和指针实现)
- (UVA
- bzoj 1632: [Usaco2007 Feb]Lilypad Pond SPFA
- 任务、进程、线程之间的区别
- openwrt各种奇怪问题总结(对C++依赖)
- POJ