(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 ...
随机推荐
- Kafka 的这些原理你知道吗
如果只是为了开发 Kafka 应用程序,或者只是在生产环境使用 Kafka,那么了解 Kafka 的内部工作原理不是必须的.不过,了解 Kafka 的内部工作原理有助于理解 Kafka 的行为,也利用 ...
- linux根文件系统的挂载过程详解
一:前言 前段时间在编译kernel的时候发现rootfs挂载不上.相同的root选项设置旧版的image却可以.为了彻底解决这个问题.研究了一下rootfs的挂载过程.特总结如下,希望能给这部份知识 ...
- 谷歌浏览器调用activex控件方法
原文转自 https://jingyan.baidu.com/article/af9f5a2d0ebe5543140a4596.html activex是由微软开发,所以在支持上,目前原生态支持的只有 ...
- CSS Cursor屬性 (光标停留显示)
<html> <body> <p>请把鼠标移动到单词上,可以看到鼠标指针发生变化:</p> <span style="cursor:au ...
- 3_PHP表达式_4_PHP运算符
以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. 3.4.1 算术运算符 <?php $num1 = -10; $num2 = -4; $num3 = $nu ...
- 时间都去哪儿了?开源一个统计iPhone上App运行时间和打开次数的小工具【iOS8已失效】
如今,大家每天都有大量时间花在手机上,但是,大家有没有想过自己的时间都花在哪些App上了呢?相信很多人都有这样的需求,不过iOS系统本身并不能显示每个App的运行时间和次数,因此,本人写了这样一个小工 ...
- iOS 数据源切换混乱问题
问题场景 这个问题遇到是偶然的,正常来说是不会出现的.但是有时候在一些极端操作情况下,还是出现了. 现在我说明下这个场景.页面上是一个tableview,那对应的有一个dataSource,页面顶部有 ...
- jenkins的理解及安装
目录 一.理论概述 二.安装 一.理论概述 Jenkins的介绍 Jenkins是一个基于MIT License协议的开源软件项目,是基于Java开发的一种持续集成(CI)工具,用于监控持续重复的 ...
- pyhton中map和reduce
from functools import reduce import numpy as np ''' reduce[function, sequence[, initial]]使用 1.functi ...
- word中快捷键查看与设定
很多时候,我们在编辑word文档的时候,为了快速方便都使用快捷键,常用的快捷键大家都知道,但是不常用的是不是就比较懵圈,本文就来告诉你怎么查看与设置word的快捷键. 我使用的word2016 第一步 ...