Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树
思路:
(我也不知道这是不是正解)
ST表预处理出来原数列的两点之间的min
再搞一个动态开节点线段树
节点记录ans 和标记
lazy=-1 当前节点的ans可用 lazy=0 没被覆盖过 else 区间覆盖
push_up的时候要注意好多细节,,
数组尽量往大开
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=;
int n,k,q,op,xx,b[N],f[N][],lson[N<<],rson[N<<],root,cnt;
int lazy[N<<],ans[N<<],base[N];//lazy=-1 废了 lazy=0 原数列 else 区间覆盖
int RMQ(int x,int y){
int t=base[y-x+];
return min(f[x][t],f[y-(<<t)+][t]);
}
int qry(int l,int r){
if(r-l>=n)return RMQ(,n);
else{
l=(l-)%n+,r=(r-)%n+;
if(l>r)return min(RMQ(,r),RMQ(l,n));
else return RMQ(l,r);
}
}
void push_down(int pos){
if(!lson[pos])lson[pos]=++cnt;lazy[lson[pos]]=lazy[pos];
if(!rson[pos])rson[pos]=++cnt;lazy[rson[pos]]=lazy[pos];
}
void insert(int l,int r,int &pos,int L,int R,int wei){
if(!pos)pos=++cnt;
// printf("l=%lld r=%lld pos=%d\n",l,r,pos);
if(lazy[pos]&&~lazy[pos]){
ans[pos]=lazy[pos];
push_down(pos);
lazy[pos]=-;
}
if(l>=L&&r<=R){ans[pos]=lazy[pos]=xx;return;}
int mid=(l+r)>>;
if(mid<L)insert(mid+,r,rson[pos],L,R,wei);
else if(mid>=R)insert(l,mid,lson[pos],L,R,wei);
else insert(l,mid,lson[pos],L,R,wei),insert(mid+,r,rson[pos],L,R,wei);
int temp=0x3f3f3f3f;
if(lson[pos]){
if(!lazy[lson[pos]])temp=qry(l,mid);
else if(lazy[lson[pos]]==-)temp=ans[lson[pos]];
else temp=lazy[lson[pos]];
}
else temp=qry(l,mid);
if(lazy[rson[pos]]){
if(!lazy[rson[pos]])temp=min(temp,qry(mid+,r));
else if(lazy[rson[pos]]==-)temp=min(temp,ans[rson[pos]]);
else temp=min(temp,lazy[rson[pos]]);
}
else temp=min(temp,qry(mid+,r));
ans[pos]=temp,lazy[pos]=-;
}
int query(int l,int r,int pos,int L,int R){
if(l==L&&r==R){
if(lazy[pos]==-)return ans[pos];
else if(!lazy[pos])return qry(l,r);
else return lazy[pos];
}
if(!pos)return qry(L,R);
if(lazy[pos]&&~lazy[pos])return lazy[pos];
int mid=(l+r)>>;
if(mid<L)return query(mid+,r,rson[pos],L,R);
else if(mid>=R)return query(l,mid,lson[pos],L,R);
else return min(query(l,mid,lson[pos],L,mid),query(mid+,r,rson[pos],mid+,R));
}
void DFS(int l,int r,int pos){
printf("l=%d r=%d pos=%d lazy[pos]=%d ans[pos]=%d\n",l,r,pos,lazy[pos],ans[pos]);
int mid=(l+r)>>;
if(lson[pos])DFS(l,mid,lson[pos]);
if(rson[pos])DFS(mid+,r,rson[pos]);
}
int main(){
scanf("%d%d",&n,&k);
base[]=-;
for(int i=;i<=n;i++)scanf("%d",&b[i]),f[i][]=b[i],base[i]=base[i>>]+;
for(int j=;j<=;j++)
for(int i=;i+(<<(j-))<=n;i++)
f[i][j]=min(f[i][j-],f[i+(<<(j-))][j-]);
scanf("%d",&q);
while(q--){
int l,r;
scanf("%d%d%d",&op,&l,&r);
if(op==){
scanf("%d",&xx);
insert(,n*k,root,l,r,xx);
}
else{
printf("%d\n",query(,n*k,root,l,r));
}
// DFS(1,1ll*n*k,1);
}
}
/*
8 4
5 6 1 3 3 2 9 6 14
1 10 19 2
2 14 26 */
Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树的更多相关文章
- codeforces 803G Periodic RMQ Problem
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...
- 洛谷P3313 [SDOI2014]旅行(树链剖分 动态开节点线段树)
题意 题目链接 Sol 树链剖分板子 + 动态开节点线段树板子 #include<bits/stdc++.h> #define Pair pair<int, int> #def ...
- 洛谷P3120 [USACO15FEB]牛跳房子(动态开节点线段树)
题意 题目链接 Sol \(f[i][j]\)表示前\(i\)行\(j\)列的贡献,转移的时候枚举从哪里转移而来,复杂度\(O(n^4)\) 然后考虑每一行的贡献,动态开节点线段树维护一下每种颜色的答 ...
- BZOJ4636: 蒟蒻的数列(动态开节点线段树)
题意 题目链接 Sol 直接上动态开节点线段树 因为只有一次询问,所以中途不需要下传标记 #include<bits/stdc++.h> #define LL long long usin ...
- 洛谷P3960 列队(动态开节点线段树)
题意 题目链接 Sol 看不懂splay..,看不懂树状数组... 只会暴力动态开节点线段树 观察之后不难发现,我们对于行和列需要支持的操作都是相同的:找到第\(k\)大的元素并删除,在末尾插入一个元 ...
- Codeforces 803G Periodic RMQ Problem 线段树
Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...
- 洛谷P4632 [APIO2018] New Home 新家(动态开节点线段树 二分答案 扫描线 set)
题意 题目链接 Sol 这题没有想象中的那么难,但也绝对不简单. 首先把所有的询问离线,按照出现的顺序.维护时间轴来处理每个询问 对于每个询问\((x_i, y_i)\),可以二分答案\(mid\). ...
- BZOJ 3065 替罪羊树+动态开节点线段树
思路: RT 可以看VFK的题解 我写了半天拍了半天... 不过是$nlog^2n$的 要写垃圾回收的 线段树 如果某个节点的sum是0 也可以free掉 //By SiriusRen #inclu ...
- codeforces 893F - Physical Education Lessons 动态开点线段树合并
https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...
随机推荐
- 元组tuple类型内置方法
目录 元组tuple类型内置方法 用途 定义 常用操作+内置方法 优先掌握 存一个值or多个值 有序or无序 可变or不可变 元组tuple类型内置方法 元组是不可变的列表,在定义完成后后面就不可以进 ...
- 7-26 Windows消息队列
7-26 Windows消息队列(25 分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中. ...
- java8新特性 日期
1. LocalDateTime 2. Instant package com.atguigu.java8; import java.time.DayOfWeek; import java.time. ...
- JavaSE 学习笔记之新特性之泛型(二十)
泛型:jdk1.5版本以后出现的一个安全机制.表现格式:< > 好处: 1:将运行时期的问题ClassCastException问题转换成了编译失败,体现在编译时期,程序员就可以解决问题. ...
- Display PowerPoint slide show within a VB form or control window
The example below shows how to use VB form/control as a container application to display a PowerPoin ...
- vim高亮显示当前行列
vim高亮显示当前行: set cursorline vim高亮显示当前列: set cursorcolumn
- ISO 7064:1983.MOD11-2校验码计算法 : (身份证校验码-18位)
/* 假设某一17位数字是 17位数字 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 加权因子 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 计算17位 ...
- zoj——1311 Network
Network Time Limit: 2 Seconds Memory Limit: 65536 KB A Telephone Line Company (TLC) is establis ...
- Android GIS开发系列-- 入门季(6)GraphicsLayer添加文字与图片标签
一.GraphicsLayer添加图片 GraphicLayer添加图片Graphic,要用到PictureMarkerSymbol,也是样式的一种.添加代码如下: Drawable drawable ...
- java界面编程(9) ------ 列表框
本文是自己学习所做笔记,欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 列表框和JComboBox组合框明显不同,这不不过体如今外观上. 当激活JCom ...