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 ...
随机推荐
- Could not create connection to database server. Attempted reconnect 3 times. Giving up.错误
项目是基于springboot框架,昨天从git上pull代码之后也没有具体看更改的地方,结果运行的时候就报错了. java.sql.SQLNonTransientConnectionExceptio ...
- [HNOI2012]矿场搭建(割点)
[HNOI2012]矿场搭建 题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出 ...
- Eclipse反编译插件 Enhanced Class Decompiler
因为jar包中的源码都是经过反编译的,所以需要安装插件才能查看到源码,此处介绍的是 Enhanced Class Decompiler 插件. 打开Eclipse,Help --> Eclips ...
- Atitit.软件开发的终于的设计 dsl化,ast化(建立ast, 解析运行ast)
Atitit.软件开发的终于的设计 dsl化,ast化(建立ast, 解析运行ast) 1. 使用js,html 撰写dsl 1 1.1. 架构图 1 1.2. html 2 1.3. Js 2 1. ...
- java 究竟老年代和年轻代的比例为多大合适呢?
眼下我还没有这方面过多的经验,和切身体会 只是以我眼下的水平看来,年轻代不宜大,假设年轻代大会导致转为老年代的时候,老年代撑不下.导致full gc.回收停顿时间过长
- AFNetworking框架的使用
#import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...
- modSecurity规则学习(七)——防止SQL注入
1.数字型SQL注入 /opt/waf/owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf"] [lin ...
- SQL Source Control
https://documentation.red-gate.com/display/SOC5/SQL+Source+Control+5+documentation Working with migr ...
- thinkphp5项目--企业单车网站(六)
thinkphp5项目--企业单车网站(六) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Websitehttps:/ ...
- Aizu - 2555 Everlasting Zero 模拟
Aizu - 2555 Everlasting Zero 题意:学习技能,每个技能有不同的要求,问能否学习全部特殊技能 思路:枚举每两个技能,得到他们的先后学习关系,如果两个都不能先学的话就是No了, ...