POJ 4047 Garden
Garden
This problem will be judged on PKU. Original ID: 4047
64-bit integer IO format: %lld Java class name: Main
Input
Output
For each query with p = 2, print the maximum sum of the aesthetics values in one shot in interval [x, y].
Sample Input
1
5 7 3
-1 2 -4 6 1
2 1 5
2 1 3
1 2 1
2 1 5
2 1 4
0 2 4
2 1 5
Sample Output
4
-3
3
1
6
Source
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
struct node {
int lt,rt,maxv,lazy;
} tree[maxn<<];
int d[maxn],a[maxn],n,m,k;
void pushup(int v) {
tree[v].maxv = max(tree[v<<].maxv + tree[v<<].lazy,tree[v<<|].maxv+tree[v<<|].lazy);
}
void pushdown(int v) {
if(tree[v].lazy) {
tree[v<<].lazy += tree[v].lazy;
tree[v<<|].lazy += tree[v].lazy;
tree[v].lazy = ;
}
}
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].lazy = ;
if(lt == rt) {
tree[v].maxv = d[tree[v].lt + k - ] - d[tree[v].lt-];
return;
}
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
pushup(v);
}
void update(int lt,int rt,int val,int v){
if(lt <= tree[v].lt && rt >= tree[v].rt){
tree[v].lazy += val;
return;
}
pushdown(v);
if(lt <= tree[v<<].rt) update(lt,rt,val,v<<);
if(rt >= tree[v<<|].lt) update(lt,rt,val,v<<|);
pushup(v);
}
int query(int lt,int rt,int v){
if(lt <= tree[v].lt && rt >= tree[v].rt) return tree[v].maxv + tree[v].lazy;
pushdown(v);
int ans = -0x3f3f3f3f;
if(lt <= tree[v<<].rt) ans = max(ans,query(lt,rt,v<<));
if(rt >= tree[v<<|].lt) ans = max(ans,query(lt,rt,v<<|));
pushup(v);
return ans;
}
int main() {
int T,p,x,y;
scanf("%d",&T);
while(T--) {
scanf("%d %d %d",&n,&m,&k);
for(int i = ; i <= n; ++i) {
scanf("%d",d+i);
a[i] = d[i];
d[i] += d[i-];
}
build(,n-k+,);
while(m--){
scanf("%d %d %d",&p,&x,&y);
if(!p){
update(max(,x - k + ),min(n-k+,x),y - a[x],);
a[x] = y;
}else if(p == ){
update(max(,x - k + ),min(n-k+,x),a[y] - a[x],);
update(max(,y - k + ),min(n-k+,y),a[x] - a[y],);
swap(a[x],a[y]);
}else if(p == ) printf("%d\n",query(x,y-k+,));
}
}
return ;
}
POJ 4047 Garden的更多相关文章
- POJ 4047 Garden 线段树 区间更新
给出一个n个元素的序列,序列有正数也有负数 支持3个操作: p x y 0.p=0时,把第x个的值改为y 1.p=1时,交换第x个和第y个的值 2.p=2时,问区间[x,y]里面连续k个的子序列的最大 ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
随机推荐
- 关于zxing生成二维码,在微信长按识别不了问题
在做校园学生到校情况签到系统时,我采用了zxing作为二维码生成工具.在测试的时候使用微信打开连接发现.我长按我的二维码之后,总是不会出现以下这种识别二维码的选项. 这就大大的降低了用户的体验,只能大 ...
- js001 ---- async
Node.js异步流,详细见https://caolan.github.io/async/docs.html#parallel 1, async 用的比较多的是 waterfall, 瀑布流, 就是每 ...
- [Python] ndArray of numpy
NumPy Reference: Mathematical functions numpy.sum: Sum of elements - along rows, columns or all nump ...
- cocos2d-js导弹跟踪算法(一边追着目标移动一边旋转角度)
跟踪导弹 function(targetPosition){ // 让物体朝目标移动的方法 ; var targetPoint = targetPosition; var thisPoint = cc ...
- CF 558A(Lala Land and Apple Trees-暴力)
A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes input ...
- Armbian hostname and WiFi configuration
In previous post i have described installation of Armbian on Orange Pi PC Plus. Now is the time for ...
- decimal.ToString("#0.00")与decimal.ToString("#.##")的区别
decimal decTemp = 2.1m; Console.WriteLine(decTemp.ToString("#0.00")); //输出2.10 Console.Wri ...
- sql的四大函数
字符串函数: 1.charindex(字符串表达式 1, 字符串表达式2[,整数表达式]) select charindex('ab','BCabTabD')返回 3 select charindex ...
- Codefroces 852 G. Bathroom terminal
G. Bathroom terminal Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to p ...
- android开源项目---View篇
本文转载自:http://blog.csdn.net/likebamboo/article/details/19080739 主要介绍那些不错个性化的View,包括ListView.ActionBar ...