(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 ...
随机推荐
- linux学习之路(二)--centos7安装Redis(单点)
一.安装redis 1.进入/usr/local/,新建services目录,进入该目录,下载redis wget http://download.redis.io/releases/redis-4. ...
- flume-ng version出现错误Error: Could not find or load main class org.apache.flume.tools.GetJavaPrope的解决办法
错误: 找不到或无法加载主类 org.apache.flume.tools.GetJavaProperty或者Error: Could not find or load main class org. ...
- js获取网页和屏幕高度
获取浏览器窗口的可视区域高度和宽度 document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象 ...
- 关于使用sublime的一些报错异常退出的解决方法
1.我用Sublime Text 3,装了一些插件,现在一打开软件就提示plugin_host has exited unexpectedly,如下图 解决方案 :
- you might not need jquery
What's the oldest version of IE you need to support? IE10 /**json**/ var request = new XMLHttpReques ...
- 微信小程序 之wxml保留小数点后两位数的方法及转化为字符串的方法
原理:wxml中不能直接使用较高级的js语法,如‘.toFixed’,‘toString()’,但可以通过引入wxs模块实现效果 1.新建`filter.wxs` var filters = { ...
- Android笔记(二十五) ListView的缓存机制与BaseAdapter
之前接触了ListView和Adapter,Adapter将数据源和View连接起来,实际应用中,我们要显示的数据往往有很多,而屏幕只有那么大,系统只能屏幕所能显示的内容,当我们滑动屏幕,会将旧的内容 ...
- Java上传图片到服务器
HTML页面的标签 <div id="div_selectpic" align="right" style="width: 300px;font ...
- NTFS文件系统概述
NTFS简介 NTFS是Windows NT家族1的限制级专用的文件系统2.Win95.Win98识别不了NTFS,只有支持NT内核的OS才能识别NTFS文件系统.当前,NTFS取代了老式的FAT文件 ...
- roles
nginx 官方下载 [root@ansible roles]# tree yngx yngx ├── defaults ├── files │ ├── blog.conf │ ├── edu ...