思路:

(我也不知道这是不是正解)

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表+动态开节点线段树的更多相关文章

  1. codeforces 803G Periodic RMQ Problem

    codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...

  2. 洛谷P3313 [SDOI2014]旅行(树链剖分 动态开节点线段树)

    题意 题目链接 Sol 树链剖分板子 + 动态开节点线段树板子 #include<bits/stdc++.h> #define Pair pair<int, int> #def ...

  3. 洛谷P3120 [USACO15FEB]牛跳房子(动态开节点线段树)

    题意 题目链接 Sol \(f[i][j]\)表示前\(i\)行\(j\)列的贡献,转移的时候枚举从哪里转移而来,复杂度\(O(n^4)\) 然后考虑每一行的贡献,动态开节点线段树维护一下每种颜色的答 ...

  4. BZOJ4636: 蒟蒻的数列(动态开节点线段树)

    题意 题目链接 Sol 直接上动态开节点线段树 因为只有一次询问,所以中途不需要下传标记 #include<bits/stdc++.h> #define LL long long usin ...

  5. 洛谷P3960 列队(动态开节点线段树)

    题意 题目链接 Sol 看不懂splay..,看不懂树状数组... 只会暴力动态开节点线段树 观察之后不难发现,我们对于行和列需要支持的操作都是相同的:找到第\(k\)大的元素并删除,在末尾插入一个元 ...

  6. Codeforces 803G Periodic RMQ Problem 线段树

    Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...

  7. 洛谷P4632 [APIO2018] New Home 新家(动态开节点线段树 二分答案 扫描线 set)

    题意 题目链接 Sol 这题没有想象中的那么难,但也绝对不简单. 首先把所有的询问离线,按照出现的顺序.维护时间轴来处理每个询问 对于每个询问\((x_i, y_i)\),可以二分答案\(mid\). ...

  8. BZOJ 3065 替罪羊树+动态开节点线段树

    思路: RT 可以看VFK的题解 我写了半天拍了半天... 不过是$nlog^2n$的 要写垃圾回收的 线段树 如果某个节点的sum是0  也可以free掉 //By SiriusRen #inclu ...

  9. codeforces 893F - Physical Education Lessons 动态开点线段树合并

    https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...

随机推荐

  1. ubuntu jdk和tomcat配置

    先查看linux的版通过file /sbin/init命令,下载对应版本的jdk. 我的ubuntu是64位的(桌面系统),所以下载的是jdk-7u71-linux-x64.tar.gz 在home的 ...

  2. JMeter测试websocket

    今天公司要测websocket,搞了一天踩了不少坑,关键是还没爬出来,BOSS让回家再理理思路,没办法到家就开干. 一.家里玩的还是2.1的,为了少踩坑,先下个JMeter5.1.1(他们说4版本也行 ...

  3. CSC

    CSC CSC Table of Contents 1. account 2. Contacts 3. <国家公派留学人员预订回国机票说明> 4. 回国手续 4.1. 申办及开具<留 ...

  4. 洛谷 3398 仓鼠找sugar 【模板】判断树上两链有交

    [题解] 题意就是判断树上两条链是否有交.口诀是“判有交,此链有彼祖”.即其中一条链的端点的Lca在另一条链上. 我们设两条链的端点的Lca中深度较大的为L2,对L2与另一条链的两个端点分别求Lca, ...

  5. java 项目连接MySQL数据库

    1.导入jar包 mysql-connector-java-5.1.35百度云链接如下: 链接:https://pan.baidu.com/s/1DPvIwU_An4MA3mU5bQa6VA 密码:5 ...

  6. HDU 1228 字符串到数字的转化

    一道水题,练练字符串的输入输出 #include <cstdio> #include <cstring> using namespace std; ] , s2[]; int ...

  7. Codeforces Round #260 (Div. 2) D

    D. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. HDU5266 LCA 树链剖分LCA 线段树

    HDU5266 LCA Description 给一棵 n 个点的树,Q 个询问 [L,R] : 求点 L , 点 L+1 , 点 L+2 -- 点 R 的 LCA. Input 多组数据. The ...

  9. (12)GrabCut前景提取

    import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread('opencv-python-foregr ...

  10. Mysql优化和执行计划

    SQL优化准则 禁用select * 使用select count(*) 统计行数 尽量少运算 尽量避免全表扫描,如果可以,在过滤列建立索引 尽量避免在where子句对字段进行null判断 尽量避免在 ...