BZOJ 4355: Play with sequence
调了好久,还是黑盒测试有前途
我以前怕不是学了假的吉利线段树(我第一次知道还要记次小值去更新的........)
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int n,m,tr_sz[1500005],a[300005];
ll tag_cov[1500005],tr_min[1500005],tag_add[1500005],tr_sc[1500005];
void update_cov(int t,ll c,int l,int r){
tag_add[t]=0;
tag_cov[t]=tr_min[t]=c,tr_sc[t]=1ll<<60;
//if (t==8) printf("%d %d\n",l,r);
tr_sz[t]=r-l+1;
} void update_add(int t,ll c){
tag_add[t]+=c;
tr_min[t]+=c;
if (tr_sc[t]!=1ll<<60) tr_sc[t]+=c;
}
void update(int t,int l,int r){
ll Min=min(tr_min[t<<1],tr_min[t<<1|1]);
tr_min[t]=Min;
tr_sz[t]=(tr_min[t<<1]==Min?tr_sz[t<<1]:0)+(tr_min[t<<1|1]==Min?tr_sz[t<<1|1]:0);
tr_sc[t]=min(tr_min[t<<1]==Min?tr_sc[t<<1]:tr_min[t<<1],tr_min[t<<1|1]==Min?tr_sc[t<<1|1]:tr_min[t<<1|1]);
if (tr_sz[t]>r-l+1) printf("!!!\n");
}
void update_min(int t,ll c){
tr_min[t]=max(tr_min[t],c);
}
void push_down(int t,int l,int r){
int mid=(l+r)>>1;
if (tag_cov[t]!=-1) update_cov(t<<1,tag_cov[t],l,mid),update_cov(t<<1|1,tag_cov[t],mid+1,r);
if (tag_add[t]) update_add(t<<1,tag_add[t]),update_add(t<<1|1,tag_add[t]);
update_min(t<<1,tr_min[t]),update_min(t<<1|1,tr_min[t]);
tag_cov[t]=-1,tag_add[t]=0;
}
void build(int t,int l,int r){
tag_cov[t]=-1,tag_add[t]=0;
if (l==r){
tr_min[t]=a[l],tr_sc[t]=1ll<<60,tr_sz[t]=1;
return;
}
int mid=(l+r)>>1;
build(t<<1,l,mid);
build(t<<1|1,mid+1,r);
update(t,l,r);
}
void modify_cov(int t,int l,int r,int x,int y,ll c){
if (r<x || l>y) return;
if (l>=x && r<=y){
update_cov(t,c,l,r);
return;
}
push_down(t,l,r);
int mid=(l+r)>>1;
modify_cov(t<<1,l,mid,x,y,c);
modify_cov(t<<1|1,mid+1,r,x,y,c);
update(t,l,r);
}
void modify_add(int t,int l,int r,int x,int y,ll c){
if (r<x || l>y) return ;
if (l>=x && r<=y){
update_add(t,c);
return;
}
push_down(t,l,r);
int mid=(l+r)>>1;
modify_add(t<<1,l,mid,x,y,c);
modify_add(t<<1|1,mid+1,r,x,y,c);
update(t,l,r);
}
void modify_0(int t,int l,int r,int x,int y){
if (r<x || l>y) return;
if (tr_min[t]>=0) return;
if (l>=x && r<=y && tr_sc[t]>0){
update_min(t,0);
return;
}
push_down(t,l,r);
int mid=(l+r)>>1;
modify_0(t<<1,l,mid,x,y);
modify_0(t<<1|1,mid+1,r,x,y);
update(t,l,r);
}
int query(int t,int l,int r,int x,int y){
if (r<x || l>y) return 0;
if (tr_min[t]) return 0;
if (l>=x && r<=y) {
//printf("%d %d %d %d\n",l,r,tr_sz[t],t);
return tr_sz[t];
}
push_down(t,l,r);
int mid=(l+r)>>1;
return query(t<<1,l,mid,x,y)+query(t<<1|1,mid+1,r,x,y);
}
int main(){
scanf("%d%d",&n,&m);
for (int i=1; i<=n; i++) scanf("%d",&a[i]);
build(1,1,n);
while (m--){
int cas,l,r,c;
scanf("%d%d%d",&cas,&l,&r);
if (cas==1 || cas==2) scanf("%d",&c);
if (cas==1) modify_cov(1,1,n,l,r,c);
if (cas==2) modify_add(1,1,n,l,r,c),modify_0(1,1,n,l,r);
if (cas==3) printf("%d\n",query(1,1,n,l,r));
}
return 0;
}
BZOJ 4355: Play with sequence的更多相关文章
- BZOJ.4355.Play with sequence(线段树)
题目链接 问题在于操作二.操作二可以拆分成:区间加\(C\).区间(对\(0\))取\(\max\). 注意到操作一的\(C\)都是非负数,即数列中不会出现负数,所以我们直接维护最小值和最小值出现的次 ...
- bzoj 1005 组合数学 Purfer Sequence
这题需要了解一种数列: Purfer Sequence 我们知道,一棵树可以用括号序列来表示,但是,一棵顶点标号(1~n)的树,还可以用一个叫做 Purfer Sequence 的数列表示 一个含有 ...
- bzoj 2656 [Zjoi2012]数列(sequence) 递推+高精度
2656: [Zjoi2012]数列(sequence) Time Limit: 2 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Descri ...
- 【BZOJ】1367: [Baltic2004]sequence
题意 给\(n(n \le 10^6)\)个数的序列\(a\),求一个递增序列\(b\)使得\(\sum_{i=1}^{n} |a_i-b_i|\)最小. 分析 神题啊不会. 具体证明看黄源河论文&l ...
- bzoj 2656 [Zjoi2012]数列(sequence)(高精度)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2656 [题意] 计算大数递推式 [思路] 高精度 [代码] #include<c ...
- bzoj 1367 [ Baltic 2004 ] sequence —— 左偏树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1367 好题啊!论文上的题: 论文上只给出了不下降序列的求法: 先考虑特殊情况,如果原序列上升 ...
- BZOJ 3043 [Poetize6] IncDec Sequence
题目描述 给定一个长度为n的数列$a_1,a_2,--,a_n$,每次可以选择一个区间[l,r],使这个区间内的数都加1或者都减1. 请问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 1005 [HNOI2008] 明明的烦恼(组合数学 Purfer Sequence)
题目大意 自从明明学了树的结构,就对奇怪的树产生了兴趣...... 给出标号为 1 到 N 的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树? Input 第一行为 N( ...
随机推荐
- JSONModel 简单例子
// ProductModel.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All righ ...
- css样式优先级问题
官方表述的CSS样式优先级如下: 通用选择器(*) < 元素(类型)选择器 < 类选择器 < 属性选择器 < 伪类 < ID 选择器 < 内联样式 那么,我们来举个 ...
- Date-DateFormat-Calendar-Math-regex
一.Date类(java.util) 作用:表示时间的类,精确到毫秒,以GMT 1970年1月1日0点0分0秒起算 构造方法: Data() ---获取当前时间 Date(long ...
- Android中的GreenDao框架修改数据库的存储路径
目前android中比较热门的数据库框架有greenDAO.OrmLite.AndrORM,其中我比较喜欢用GreenDao,其运行效率最高,内存消耗最少,性能最佳.具体怎么使用GreenDao,网上 ...
- escape,encodeURI,encodeURIComponent 之间的区别和使用
escape(目前已经被淘汰)是对字符串(string)进行编码(而另外两种是对URL),不会对下列字符编码 ASCII字母 数字 @*/+ 最关键的是,当你需要对URL编码时,请忘记这个方法,这 ...
- UVA 177 PaperFolding 折纸痕 (分形,递归)
著名的折纸问题:给你一张很大的纸,对折以后再对折,再对折……每次对折都是从右往左折,因此在折了很多次以后,原先的大纸会变成一个窄窄的纸条.现在把这个纸条沿着折纸的痕迹打开,每次都只打开“一半”,即把每 ...
- UVA 211 The Domino Effect 多米诺效应 (回溯)
骨牌无非两种放法,横着或竖着放,每次检查最r,c最小的没访问过的点即可.如果不能放就回溯. 最外面加一层认为已经访问过的位置,方便判断. #include<bits/stdc++.h> ; ...
- C++链表简单的应用
学生管理系统,输入学生的姓名和学号,然后再输出: #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <stdlib ...
- 01_13_Struts_默认Action
01_13_Struts_默认Action 1. 配置struts默认Action <package name="default" namespace="/&quo ...
- 如何在vue项目中引用Iview
iview 安装 npm install iview --save 引入iview import Vue from 'vue' import App from './App' import route ...