gss2调了一下午,至今还在wa。。。

我的做法是:对于询问按右区间排序,利用splay记录最右的位置。对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点。对于没有出现过的,直接插入。询问时直接统计区间的最大子段和。

gss2没能调出bug,所以看了一下以下的gss3,发现跟gss1基本一样。直接上代码

以上的做法是错的,对于这种数据就过不了。姿势不对,囧

4
4 -2 3 -2
1
1 4

GSS Can you answer these queries III

题目:给出一个数列,有两种操作:

0.把第x项变为y

1.询问区间[l,r]的最大子段和

分析:
线段树简单区间操作。跟gss1基本一样。。。

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue
#define cmax(x,y) x = max(x,y)
#define cmin(x,y) x = min(x,y)
#define Clear(x) memset(x,0,sizeof(x))
/* #pragma comment(linker, "/STACK:1024000000,1024000000") int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) ); */ /******** program ********************/ const int MAXN = 100005; int a[MAXN]; struct segTree{
int l,r,lx,rx,mx,sum;
inline int mid(){
return (l+r)>>1;
}
}tree[MAXN<<2]; inline void Union(segTree& now,segTree l,segTree r){
now.lx = max( l.lx , l.sum+max(0,r.lx) );
now.rx = max( r.rx , r.sum+max(0,l.rx) );
now.mx = max( l.rx+r.lx , max(l.mx,r.mx) );
now.sum = l.sum+r.sum;
} void build(int l,int r,int rt){
tree[rt].l = l;
tree[rt].r = r;
if(l==r){
tree[rt].lx = tree[rt].rx = tree[rt].sum = tree[rt].mx = a[l];
return;
}
int mid = tree[rt].mid();
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
Union(tree[rt],tree[rt<<1],tree[rt<<1|1]);
} void modify(int pos,int c,int rt){
if(tree[rt].l==tree[rt].r){
tree[rt].lx = tree[rt].rx = tree[rt].mx = tree[rt].sum = c;
return;
}
int mid = tree[rt].mid();
if(pos<=mid)modify(pos,c,rt<<1);
else modify(pos,c,rt<<1|1);
Union(tree[rt],tree[rt<<1],tree[rt<<1|1]);
} segTree ask(int l,int r,int rt){
if(l<=tree[rt].l&&r>=tree[rt].r)
return tree[rt];
int mid = tree[rt].mid();
segTree ans;
if(r<=mid) ans = ask(l,r,rt<<1);
else if(l>mid) ans = ask(l,r,rt<<1|1);
else{
segTree a = ask(l,r,rt<<1);
segTree b = ask(l,r,rt<<1|1);
Union( ans,a,b );
}
Union(tree[rt],tree[rt<<1],tree[rt<<1|1]);
return ans;
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif int m,n,x,y,op;
while(~RD(n)){
rep1(i,n)
RD(a[i]);
build(1,n,1);
RD(m);
while(m--){
RD3(op,x,y);
if(op){
segTree now = ask(x,y,1);
printf("%d\n",now.mx);
}else
modify(x,y,1);
}
} return 0;
}

  

GSS3 SPOJ 1716. Can you answer these queries III gss1的变形的更多相关文章

  1. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  2. 数据结构(线段树):SPOJ GSS3 - Can you answer these queries III

    GSS3 - Can you answer these queries III You are given a sequence A of N (N <= 50000) integers bet ...

  3. 「 SPOJ GSS3 」 Can you answer these queries III

    # 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...

  4. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

  5. 线段树 SP1716 GSS3 - Can you answer these queries III

    SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...

  6. Can you answer these queries III

    Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改 ...

  7. Can you answer these queries III(线段树)

    Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...

  8. SPOJ 1557. Can you answer these queries II 线段树

    Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/pr ...

  9. bzoj 2482: [Spoj GSS2] Can you answer these queries II 线段树

    2482: [Spoj1557] Can you answer these queries II Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 145 ...

随机推荐

  1. 【转】Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)

    Android-Universal-Image-Loader 原文地址:http://blog.csdn.net/vipzjyno1/article/details/23206387 这个图片异步加载 ...

  2. SVN安装与使用

    来自:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html SVN服务器搭建和使用(一) Subversion是优秀的版 ...

  3. Oracle用户、权限、角色管理

    Oracle 权限设置一.权限分类:系统权限:系统规定用户使用数据库的权限.(系统权限是对用户而言). 实体权限:某种权限用户对其它用户的表或视图的存取权限.(是针对表或视图而言的).   二.系统权 ...

  4. [效果]JS折叠菜单-使用方法 (Moo.Fx)

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-06-24) 用法: 1.添加JS库 CODE:<script src="prototype.lite.js& ...

  5. linux环境新增用户和所属组

    1.查看用户和组信息命令: 1.1 cat /etc/passwd /etc/passwd 存储有关本地用户的信息. 1)username        UID到名称的一种映射,用户名 2)passw ...

  6. Programming pages of Jasper Neumann

    http://programming.sirrida.de/ Discussion topics Bit permutations Download source files List of func ...

  7. SCVMM配置

    SCVMM添加工作组主机 1.准备一台物理主机并且安装WindowsServer 2012名为HV2(工作组不加域)接着添加hyper-v角色 2.把SCVMM1服务器上的SCVMM2012代理程序( ...

  8. PHP对大小写敏感问题的处理比较乱,写代码时可能偶尔出问题,所以这里总结一下。以便用到的出现错误

    推荐大家始终坚持“大小写敏感”,遵循统一的代码规范. 1. 变量名区分大小写 1 <?php 2 $abc = 'abcd'; 3 echo $abc; //输出 'abcd' 4 echo $ ...

  9. 基于jQuery向下弹出遮罩图片相册

    今天给大家分享一款基于jQuery向下弹出遮罩图片相册.单击相册图片时,一个遮罩层从上到下动画出现.然后弹出显示图片.这款插件适用浏览器:IE8.360.FireFox.Chrome.Safari.O ...

  10. 基于Ascensor.js全屏切换页面插件

    今天给大家分享一款基于Ascensor.js全屏切换页面插件,这款实例 适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗.效果图如下: 在线预览 ...