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$的所有点中权值最小的 ...
随机推荐
- ubuntu下手动配置apache2.4.12
(apache2也可以使用 sudo apt-get install apache2来安装,下面来讲解下如何手动安装配置apache2) 在安装apache2之前,先要安装apache2的依赖项,ap ...
- spring 学习(二)
public interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object ...
- lombok 插件安装
1. 下载地址: https://plugins.jetbrains.com/plugin/6317-lombok-plugin 2. 选择从本地安装.
- java多线程synchronized volatile解析
先简单说说原子性:具有原子性的操作被称为原子操作.原子操作在操作完毕之前不会线程调度器中断.即一个操作或者多个操作 要么全部执行并且执行的过程不会被任何因素打断,要么就都不执行.在Java中,对除了l ...
- mybatis example 排序 语句
mybatis example 排序 语句 IntegralInfoExample integral = new IntegralInfoExample(); integral.createCrite ...
- POJ 1811 大整数素数判断 Miller_Rabin
#include <cstdio> #include <cstring> #include <cmath> #include <ctime> #incl ...
- 【BZOJ4514】数字配对(费用流)
题意: 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ai/aj 是一个质数, 那么这两个数字可以配对,并获得 ci× ...
- 【Java基础】基本类型与运算【重要】
0. Java基本数据类型 Java的位运算(bitwise operators)直接对整数类型的位进行操作,这些整数类型包括long.int.short.char和 byte,位运算符具体如下表 ...
- Ubuntu 16.04下轻量级文件搜索工具Catfish
Catfish搜索文件速度快,但是不支持正则表达式. 安装: sudo add-apt-repository ppa:catfish-search/ppa sudo apt-get update su ...
- Ubuntu下非常规方法安装绿色软件(压缩包)
继上一篇http://www.cnblogs.com/EasonJim/p/7117567.html文章中说的常规方式安装的软件,都会自动在命令行及Dash Home中体现. 但是如果是使用压缩包进行 ...