UESTC360Another LCIS

UESTC360 Another LCIS:http://acm.uestc.edu.cn/#/problem/show/360

Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu

Status

Description

For a sequence        

, and a pair of integers   , if   and             , then the sequence        

is a CIS (Continuous Increasing Subsequence). The longest CIS of a sequence is called the LCIS (Longest Continuous Increasing Subsequence).

In this problem, we will give you a sequence first, and then some add operations and some query operations. An add operation adds a value to each member in a specified interval. For a query operation, you should output the length of the LCIS of a specified interval.

Input

The first line of the input is an integer  

, which stands for the number of test cases you need to solve.

Every test case begins with two integers  

,   , where   is the size of the sequence, and   is the number of queries.         are specified on the next line, and then   queries follow. Every query begins with a character a or q. a is followed by three integers   ,   ,   , meaning that add   to members in the interval   (including   ,   ), and q is followed by two integers   ,   , meaning that you should output the length of the LCIS of interval  

.

 

;

 

;

 

;

       

.

Output

For every test case, you should output Case #k: on a single line first, where  

indicates the case number and starts at  

. Then for every q query, output the answer on a single line. See sample for more details.

Sample Input

1
5 6
0 1 2 3 4
q 1 4
a 1 2 -10
a 1 1 -6
a 5 5 -4
q 2 3
q 4 4

Sample Output

Case #1:
4
2
1

Hint

Source

The 9th UESTC Programming Contest Preliminary

思路:虽然都是线段树,但跟上一篇不同……上一篇是单点更新,区间查询LCIS;而这篇难度有所增加,变成区间更新,区间查询LCIS……
显然需要用到lazy标记……但怎么更新呢?当一个区间内的值同时变化时,该区间内的LCIS是不变的,因此这里新开了两个数组lvalue和rvalue,
分别记录区间最左边的值和最右边的值,这样在更新时只需更新这两个值,便可达到相同的效果。其他的跟上一篇的做法大致一样

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>
using namespace std;

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define inf 0x3f3f3f3f

const int maxn= 100000+7;
typedef long long ll;
int lx[maxn<<2],mx[maxn<<2],rx[maxn<<2],color[maxn<<2];
int lvau[maxn<<2],rvau[maxn<<2];
int a[maxn];
void pushup(int rt,int len) {
    lvau[rt] = lvau[rt<<1];
    rvau[rt] = rvau[rt<<1|1];
    lx[rt] = lx[rt<<1];
    rx[rt] = rx[rt<<1|1];
    if((lx[rt] == (len-(len>>1))) && (rvau[rt<<1] < lvau[rt<<1|1]))lx[rt] += lx[rt<<1|1];
    if((rx[rt] == (len>>1)) && (rvau[rt<<1] < lvau[rt<<1|1]))rx[rt] += rx[rt<<1];
    mx[rt] = max(max(mx[rt<<1],mx[rt<<1|1]),(rvau[rt<<1] < lvau[rt<<1|1])?rx[rt<<1]+lx[rt<<1|1]:0);
}
void build(int l,int r,int rt) {
    color[rt] = 0;
    lx[rt] = rx[rt] = mx[rt] = 0;
    if(l > r)return;
    if(l == r) {
        scanf("%d",&a[l]);
        lvau[rt] = rvau[rt] = a[l];
        lx[rt] = mx[rt] = rx[rt] = 1;
        return;
    }
    int mid = l+r>>1;
    build(lson);
    build(rson);
    pushup(rt,r-l+1);
}
void pushdown(int rt) {
    if(color[rt]) {
        lvau[rt<<1] += color[rt];
        rvau[rt<<1] += color[rt];

        lvau[rt<<1|1] += color[rt];
        rvau[rt<<1|1] += color[rt];

        color[rt<<1] += color[rt];
        color[rt<<1|1] += color[rt];
        color[rt] = 0;
    }
}
void update(int L,int R,int w,int l,int r,int rt) {
    if(L <= l && r <= R) {
        color[rt] += w;
        lvau[rt] += w;
        rvau[rt] += w;
        return;
    }
    if(l > r)return;
    pushdown(rt);
    int mid = l+r>>1;
    if(L <= mid)update(L,R,w,lson);
    if(R > mid) update(L,R,w,rson);
    pushup(rt,r-l+1);
}
int query(int L,int R,int l,int r,int rt) {
    if(L <= l && r <= R) {
        return mx[rt];
    }
    int mid = l+r>>1;
    pushdown(rt);
    if(R <= mid)return query(L,R,lson);
    else if(L > mid)return query(L,R,rson);
    else {
        int ltmp = query(L,mid,lson);
        int rtmp = query(mid+1,R,rson);
        int sum = 0;
        if(lvau[rt<<1|1] > rvau[rt<<1]) {
            sum = min(mid-L+1,rx[rt<<1])+min(R-mid,lx[rt<<1|1]);
        }
        return max(sum,max(ltmp,rtmp));
    }
}
int main() {
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    int n,m,b,c,t,w,ca = 1;
    char ss[10];
    scanf("%d",&t);
    while(t--) {
        scanf("%d%d",&n,&m);
        build(1,n,1);
        printf("Case #%d:\n",ca++);
        for(int i = 1; i <= m; i++) {
            scanf("%s",ss);
            if(ss[0] == 'a') {
                scanf("%d%d%d",&b,&c,&w);
                update(b,c,w,1,n,1);
            } else {
                scanf("%d%d",&b,&c);
                printf("%d\n",query(b,c,1,n,1));
            }
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
互联网络程序设计是指在互联网上进行程序开发和设计的过程。UESTC则是我国的一所著名高校——电子科技大学。 互联网络程序设计 uestc包含了两个主要的方面:互联网络和程序设计。互联网络是指将多个计算机网络通过通信链路互相连接起来,实现信息共享和资源共享的网络系统。程序设计是指根据需求和目标,通过编写代码和设计算法,实现计算机程序的过程。 互联网络程序设计 uestc的学习内容主要包括以下几个方面: 1. 网络知识:学习互联网络的基本概念、原理和协议,如TCP/IP协议、HTTP协议等。掌握网络编程的基本技术,能够编写网络应用程序。 2. 数据通信:学习数据通信的基本原理和技术,包括数据传输的方式、数据压缩和加密等。了解网络安全和数据保护的基本知识。 3. 程序设计:学习编程语言和开发工具,如Java、C++和Python等。掌握常用的编程技巧和方法,能够设计和实现复杂的网络应用程序。 4. Web开发:学习Web开发的基本知识和技术,包括HTML、CSS、JavaScript等。能够设计和实现交互式的Web应用程序。 5. 数据库技术:学习数据库的基本原理和技术,如SQL语言和数据库管理系统。能够设计和管理数据库,实现数据的存储和检索。 通过学习互联网络程序设计 uestc,可以掌握互联网应用开发的基本技能,具备设计和实现网络应用程序的能力。这对于目前互联网行业的人才需求来说是非常重要的,也为学生提供了广阔的就业和创业机会。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值