hdu2687
来源:互联网 发布:未来教育计算机二级vb 编辑:程序博客网 时间:2024/06/03 18:08
Matrix Rotation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 512 Accepted Submission(s): 247
(1 <= k <= 10^8)described above. Process to end of file.
Each line there are n integers separated by one space.
Note that there is no extra space at the end of each line.
31 2 32 3 43 4 5 10
33 32 3134 33 3235 34 33
参考代码:
#include <stdio.h>#include<cstdio>#include<algorithm>#include <iostream>using namespace std;const int maxn=100001;int n,m;int s[maxn<<2],sl[maxn<<2],sr[maxn<<2],ss[maxn<<2];void pushup(int rt){ s[rt]=s[rt<<1]+s[rt<<1|1]; sl[rt]=max(s[rt<<1|1]+sl[rt<<1],sl[rt<<1|1]); sr[rt]=max(s[rt<<1]+sr[rt<<1|1],sr[rt<<1]); ss[rt]=max(ss[rt<<1],ss[rt<<1|1]); ss[rt]=max(ss[rt],sl[rt<<1]+sr[rt<<1|1]);}void init(int rt,int l,int r){ int m=(l+r)>>1; if(l!=r) { init(rt<<1,l,m); init(rt<<1|1,m+1,r); pushup(rt); } else { scanf("%d",&s[rt]); sl[rt]=sr[rt]=ss[rt]=s[rt]; }}void change(int rt,int l,int r,int t,int tt){ if(l==t&&r==t) { sl[rt]=sr[rt]=ss[rt]=s[rt]=tt; } else { int m=(l+r)>>1; if(m>=t) change(rt<<1,l,m,t,tt); else change(rt<<1|1,m+1,r,t,tt); pushup(rt); }}int main(){ int t,tt; while(scanf("%d%d",&n,&m)!=EOF) { init(1,1,n); while(m--) { scanf("%d%d",&t,&tt); change(1,1,n,t,tt); printf("%d\n",ss[1]); } }}