(WAWAWAWAWAWAW) G. Periodic RMQ Problem
没有联通门 : Codeforces G. Periodic RMQ Problem
/*
Codeforces G. Periodic RMQ Problem
MMP
什么动态开点线段树啊
。。。
YY了个非常可行的做法
码完后交一下发现RE了几个点。。
就思考哪里有问题
突然之间, 老泪纵横。。
MMP 我写了这是个什么玩意啊
仔细想想我TM不就是写了个全空间的主席树吗。。。。脑子有病啊。。
静言思之, 躬自悼矣。。反是不思,亦已焉哉
不写啦!
*/
#include <cmath>
#include <cstdio>
#define Max 100008
#define INF 1e8
void read (int &now)
{
now = ;
register char word = getchar ();
bool temp = false;
while (word < '' || word > '')
{
if (word == '-')
temp = true;
word = getchar ();
}
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
if (temp)
now = -now;
}
inline int min (int a, int b)
{
return a < b ? a : b;
}
inline int max (int a, int b)
{
return a > b ? a : b;
}
int N, K;
int number[Max];
struct Segment_Tree_Date
{
Segment_Tree_Date *Left, *Right;
int l, r;
int Mid;
int key;
int Flandre;
Segment_Tree_Date ()
{
Left = NULL;
Right = NULL;
key = ;
Flandre = ;
}
};
Segment_Tree_Date *Root;
int Size;
class Segment_Tree_Type
{
public :
void Build (Segment_Tree_Date *&now, int l, int r, int k)
{
if (l == r)
{
now->key = number[l - (k - ) * N];
return;
}
now->Mid = l + r >> ;
Build (now->Left, l, now->Mid, k);
Build (now->Right, now->Mid + , r, k);
now->key = min (now->Left->key, now->Right->key);
}
void Whole_Updata (Segment_Tree_Date *&now, int l, int r)
{
if (now->l == now->r)
return ;
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre;
now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre;
now->Flandre = ;
}
Whole_Updata (now->Left, l, now->Mid);
Whole_Updata (now->Right, now->Mid + , r);
now->key = min (now->Left->key, now->Right->key);
}
int Query (Segment_Tree_Date *&now, int l, int r)
{
if (l <= now->l && now->r <= r)
return now->key;
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre;
now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre;
now->Flandre = ;
}
now->key = min (now->Left->key, now->Right->key);
int res = INF;
if (l <= now->Mid)
res = Query (now->Left, l, min (now->Mid, r));
if (r > now->Mid)
res = min (res, Query (now->Right, max (now->Mid + , l), r));
return res;
}
void Change_Section_Maxn (Segment_Tree_Date *&now, int l, int r, int to)
{
if (l <= now->l && now->r <= r)
{
now->Flandre = to;
now->key = to;
return ;
}
if (now->Flandre)
{
now->Left->key = now->Flandre;
now->Right->key = now->Flandre;
now->Left->Flandre = now->Flandre;
now->Right->Flandre = now->Flandre;
now->Flandre = ;
}
if (l <= now->Mid)
Change_Section_Maxn (now->Left, l, min (now->Mid, r), to);
if (r > now->Mid)
Change_Section_Maxn (now->Right, max (now->Mid + , l), r, to);
now->key = min (now->Left->key, now->Right->key);
}
};
Segment_Tree_Type Tree;
int M;
bool is_exist[Max];
int main (int argc, char *argv[])
{
read (N);
read (K);
for (int i = ; i <= N; i++)
read (number[i]);
int type, x, y, z;
is_exist[] = true;
int now_1, now_2;
Tree.Build (Root, , N, );
register bool flag;
for (read (M); M--; )
{
flag = false;
read (type);
read (x);
read (y);
if (type == )
{
read (z);
now_1 = ceil (x * 1.0 / N);
now_2 = ceil (y * 1.0 / N);
for (int pos = now_1; pos <= now_2; pos++)
if (!is_exist[pos])
{
Tree.Build (Root, N * (pos - ) + , N * pos, pos);
flag = true;
is_exist[pos] = true;
}
if (flag)
Tree.Whole_Updata (Root, N * (now_1 - ) + , N * now_2);
Tree.Change_Section_Maxn (Root, x, y, z);
}
else
{
now_1 = ceil (x * 1.0 / N);
now_2 = ceil (y * 1.0 / N);
for (int pos = now_1; pos <= now_2; pos++)
if (!is_exist[pos])
{
Tree.Build (Root, N * (pos - ) + , N * pos, pos);
flag = true;
is_exist[pos] = true;
}
if (flag)
Tree.Whole_Updata (Root, N * (now_1 - ) + , N * now_2);
printf ("%d\n", Tree.Query (Root, x, y));
}
}
return ;
}
(WAWAWAWAWAWAW) G. Periodic RMQ Problem的更多相关文章
- Codeforces 803 G. Periodic RMQ Problem
题目链接:http://codeforces.com/problemset/problem/803/G 大致就是线段树动态开节点. 然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点 ...
- AC日记——Periodic RMQ Problem codeforces 803G
G - Periodic RMQ Problem 思路: 题目给一段序列,然后序列复制很多次: 维护序列很多次后的性质: 线段树动态开点: 来,上代码: #include <cstdio> ...
- Codeforces 803G Periodic RMQ Problem 线段树
Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...
- codeforces 803G Periodic RMQ Problem
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...
- Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树
思路: (我也不知道这是不是正解) ST表预处理出来原数列的两点之间的min 再搞一个动态开节点线段树 节点记录ans 和标记 lazy=-1 当前节点的ans可用 lazy=0 没被覆盖过 els ...
- CF803G - Periodic RMQ Problem 动态开点线段树 或 离线
CF 题意 有一个长度为n × k (<=1E9)的数组,有区间修改和区间查询最小值的操作. 思路 由于数组过大,直接做显然不行. 有两种做法,可以用动态开点版本的线段树,或者离线搞(还没搞)( ...
- CF803G Periodic RMQ Problem
简要题意 你需要维护一个序列 \(a\),有 \(q\) 个操作,支持: 1 l r x 将 \([l,r]\) 赋值为 \(x\). 2 l r 询问 \([l,r]\) 的最小值. 为了加大难度, ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- 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 ...
随机推荐
- Sping Aop日志实现(六)--日志查询功能
最终效果: 日志查询流程分析: Controller代码: Mapper:
- python 流程判断
import getpass# print("hello word") ## name= 'pangxiao'# mix_name=name# print(mix_name,nam ...
- IAT Hook 原理分析与代码编写
Ring 3层的 IAT HOOK 和 EAT HOOK 其原理是通过替换IAT表中函数的原始地址从而实现Hook的,与普通的 InlineHook 不太一样 IAT Hook 需要充分理解PE文件的 ...
- Topics in CS(difference between compile and interpret)
编译 Compile:把整个程序源代码翻译成另外一种代码,然后等待被执行,发生在运行之前,产物是「另一份代码」. 解释 Interpret:把程序源代码一行一行的读懂然后执行,发生在运行时,产物是「运 ...
- CVE-2019-11517 CSRF in Wampserver 3.1.4-3.1.8
https://www.cnblogs.com/iAmSoScArEd/ Affected product:WampServer 3.1.4-3.1.8 Offiical description:&q ...
- K2 BPM_【解决方案】从“制造”到“智造”,K2推动制造业转型升级_业务流程管理系统
近年来,中国制造业产出占全球总产品比例越来越大,是仅次于美国的全球第二大工业制造国,中国凭借巨大的制造业总量成为名副其实的“世界工厂”.然而个性化消费的兴起正在给制造企业各环节带来冲击.在现代市场环境 ...
- 用BIO手写实现Redis客户端的探究(拒绝Jedis)
在Redis的使用过程中,大多数人都是使用现成的客户端,如Jedis,Redisson,Lettuce.因此本文研究用BIO的方式手写Redis客户端尝试,对遇到的问题进行探究及总结. Redis通讯 ...
- selenium按钮
学习使用selenium第一个坑,按钮type,submit,button driver.findElement(By.id("su")).submit() driver.find ...
- RestFramework之频率组件
一.频率组件的使用 频率组件的存在对我们这web开发有着很大的影像,它的作用就是限制用户在一段时间内访问的次数. 下面让我们介绍一下频率组件怎样使用 1.首先需要导入 from rest_framew ...
- jquery中的ajax方法(备忘)
参考:https://www.cnblogs.com/tylerdonet/p/3520862.html w3school:http://www.w3school.com.cn/jquery/ajax ...