题目链接:http://codeforces.com/problemset/problem/803/G


大致就是线段树动态开节点。

然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点所代表的区间定位到原序列中,利用ST表查一下区间最小值就可以了。

定位:

 llg minn(llg l,llg r)
{
if(r-l+>=n) return mt;
l%=n;if(!l) l=n;
r%=n;if(!r) r=n;
if(l>r) return min(gw(l,n),gw(,r));
else return gw(l,r);
}

其中${gw(l,r)}$表示原序列${[l,r]}$中元素的最小值。

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define llg int
#define inf 0x7fffffff
#define maxn 500010
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg ST[maxn][],mt=inf,n,k,Q,pre[maxn],cnt; struct point
{
llg lc,rc,l,r,set,val;
}po[maxn*]; inline llg getint()
{
llg w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar(); while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} llg gw(llg l,llg r)
{
int k=pre[r-l+];
return min(ST[l][k],ST[r-(<<k)+][k]);
} llg minn(llg l,llg r)
{
if(r-l+>=n) return mt;
l%=n;if(!l) l=n;
r%=n;if(!r) r=n;
if(l>r) return min(gw(l,n),gw(,r));
else return gw(l,r);
} void make_st()
{
for(llg i=;i<=n;i++) pre[i]=pre[i>>]+;
for(llg i=;i<=n;i++) ST[i][]=getint();
for(llg i=;i<=n;i++) mt=min(mt,ST[i][]);
for(llg i=;i<=n;i++) pre[i]=pre[i>>]+;
for(llg j=;j<=;j++)
for(llg i=,u=(<<j),p=(u>>);i+u-<=n;i++)
ST[i][j]=min(ST[i][j-],ST[i+p][j-]);
cnt=,po[].l=,po[].r=n*k,po[].val=mt;
} llg new_po(llg l,llg r)
{
llg o=++cnt;
po[o].val=minn(l,r);
po[o].l=l,po[o].r=r;
return o;
} void update(llg o)
{
if (po[o].l==po[o].r) return ;
po[o].val=inf;
if (po[o].lc) po[o].val=min(po[o].val,po[po[o].lc].val);
else
{
po[o].lc=cnt+;
new_po(po[o].l,(po[o].l+po[o].r)/);
po[o].val=min(po[o].val,po[po[o].lc].val);
}
if (po[o].rc) po[o].val=min(po[o].val,po[po[o].rc].val);
else
{
po[o].rc=cnt+;
new_po((po[o].l+po[o].r)/+,po[o].r);
po[o].val=min(po[o].val,po[po[o].rc].val);
}
} void pushdown(llg o)
{
llg l=po[o].l,r=po[o].r,lc=po[o].lc,rc=po[o].rc,mid=(l+r)>>;
if (!po[o].set || l==r) return ;
if (!lc)
{
lc=cnt+;
new_po(l,mid);
}
if (!rc)
{
rc=cnt+;
new_po(mid+,r);
}
po[lc].set=po[rc].set=po[lc].val=po[rc].val=po[o].set;
po[o].set=;
po[o].lc=lc;
po[o].rc=rc;
return ;
} void modify(llg o,llg l,llg r,llg L,llg R,llg v)
{
pushdown(o);
if (o==) o=new_po(l,r);
llg mid=(l+r)>>;
if (l>=L && r<=R)
{
po[o].val=v;
po[o].set=v;
return ;
}
if (mid>=L)
{
llg son=po[o].lc;
if (po[o].lc==) po[o].lc=cnt+;
modify(son,l,mid,L,R,v);
}
if (mid<R)
{
llg son=po[o].rc;
if (po[o].rc==) po[o].rc=cnt+;
modify(son,mid+,r,L,R,v);
}
update(o);
} llg query(llg o,llg l,llg r,llg L,llg R)
{
pushdown(o);
if (o==) o=new_po(l,r);
if (l>=L && r<=R) return po[o].val;
llg mid=(l+r)>>,ans=inf;
if (mid>=L)
{
llg son=po[o].lc;
if (po[o].lc==) po[o].lc=cnt+;
ans=min(ans,query(son,l,mid,L,R));
}
if (mid<R)
{
llg son=po[o].rc;
if (po[o].rc==) po[o].rc=cnt+;
ans=min(ans,query(son,mid+,r,L,R));
}
return ans;
} int main()
{
yyj("seg");
cin>>n>>k;
make_st();
llg T=n*k;
cin>>Q;
while (Q--)
{
llg ty=getint(),l=getint(),r=getint();
if (ty==)
modify(,,T,l,r,getint());
else
printf("%d\n",query(,,T,l,r));
}
return ;
}

Codeforces 803 G. Periodic RMQ Problem的更多相关文章

  1. (WAWAWAWAWAWAW) G. Periodic RMQ Problem

    没有联通门 : Codeforces G. Periodic RMQ Problem /* Codeforces G. Periodic RMQ Problem MMP 什么动态开点线段树啊 ... ...

  2. AC日记——Periodic RMQ Problem codeforces 803G

    G - Periodic RMQ Problem 思路: 题目给一段序列,然后序列复制很多次: 维护序列很多次后的性质: 线段树动态开点: 来,上代码: #include <cstdio> ...

  3. codeforces 803G Periodic RMQ Problem

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

  4. Codeforces 803G Periodic RMQ Problem 线段树

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

  5. Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树

    思路: (我也不知道这是不是正解) ST表预处理出来原数列的两点之间的min 再搞一个动态开节点线段树 节点记录ans 和标记 lazy=-1 当前节点的ans可用  lazy=0 没被覆盖过 els ...

  6. CF803G - Periodic RMQ Problem 动态开点线段树 或 离线

    CF 题意 有一个长度为n × k (<=1E9)的数组,有区间修改和区间查询最小值的操作. 思路 由于数组过大,直接做显然不行. 有两种做法,可以用动态开点版本的线段树,或者离线搞(还没搞)( ...

  7. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  8. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  9. BZOJ3339 Rmq Problem

    [bzoj3339]Rmq Problem Description Input Output Sample Input 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 Sa ...

随机推荐

  1. [LeetCode] 120. Triangle _Medium tag: Dynamic Programming

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  2. 20175211 2018-2019-2 《Java程序设计》第五周学习总结

    目录 教材学习内容总结 第六章 接口与实现 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考试错题总结 学习进度条 参考资料 教材学习内容总结 第六章 接口与实现 6.1 接口 ...

  3. Notification web 桌面消息推送

    var NotificationHandler = { isNotificationSupported: 'Notification' in window, isPermissionGranted: ...

  4. 让我怀疑人生的bug集合

    bug1:一个人人都知道全局变量易污染,但是我就是污染不了的问题 解决:刚开始动用了session来存这个值,后来觉得太小题大做了,最后使用了闭包来解决,第一个function结束后开启第二个,起初没 ...

  5. Shadow DOM及自定义标签

    参考链接:点我 一.什么是Shadow DOM Shadow DOM,直接翻译的话就是 影子 DOM,可以理解为潜藏在 DOM 结构中并且我们无法直接控制操纵的 DOM 结构.类似于下面这种结构 Sh ...

  6. python数据类型之元组类型

    #为何要有元组,存放多个值,元组不可变,更多的是用来做查询 t=(1,[1,2,3],'a',(1,2)) #t=tuple((1,[1,2,3],'a',(1,2))) # print(type(t ...

  7. mondodb和mysql的区别

    我想从安全性和数据量这两个方面进行阐述. mongodb与mysql命令对比 传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成, MongoDB ...

  8. vuex 入坑篇

    Vuex 是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 这个状态自管理应用包含 ...

  9. go语言time包的使用

    时间类型 time.Time类型表示时间. //时间类型 func timeDemo() { now := time.Now() fmt.Println(now) //2019-04-20 13:52 ...

  10. 配置React Native 安卓开发环境

    配置主要分为以下几步: 安装node.js 安装AndroidStudio 安装React Native命令行工具 搭建React Native版本的Hello World,修改代码查看效果 第一步 ...