没有联通门 : 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的更多相关文章

  1. Codeforces 803 G. Periodic RMQ Problem

    题目链接:http://codeforces.com/problemset/problem/803/G 大致就是线段树动态开节点. 然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点 ...

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

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

  3. Codeforces 803G Periodic RMQ Problem 线段树

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

  4. codeforces 803G Periodic RMQ Problem

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

  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. CF803G Periodic RMQ Problem

    简要题意 你需要维护一个序列 \(a\),有 \(q\) 个操作,支持: 1 l r x 将 \([l,r]\) 赋值为 \(x\). 2 l r 询问 \([l,r]\) 的最小值. 为了加大难度, ...

  8. BZOJ 3489: A simple rmq problem

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

  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. java 简单操作HDFS

    创建java 项目 package com.yw.hadoop273; import org.apache.hadoop.conf.Configuration; import org.apache.h ...

  2. WPF不同方式快捷键判断

    private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { //单个按键e.Key方式判断 if (e.Key == Key ...

  3. (面试题)请用C语言实现在32位环境下,两个无符号长整数相加的函数,相加之和不能存储在64位变量中

    分析:长整数相加,将结果分为高位和低位部分,分别保存在两个32整数中. 比如:unsigned int a = 0xFFFFFFFF, unsigned int b = 0x1, 结果用unsigne ...

  4. robot framework 接口测试 http协议post请求json格式

    robot framework 接口测试 http协议post请求json格式 讲解一个基础版本.注意区分url地址和uri地址. rf和jmeter在添加服务器地址也就是ip地址的时候,只能url地 ...

  5. vue动态请求到的多重数组循环遍历,取值问题,如果某个值存在则显示,不存在则不显示。

    数据结构: 需求:我在vue页面需要拿到url值并显示图片 代码写法: 注意:一定要判断否则拿到的large对象一直是空值, 那么img.large.url将会取不到值,会报 url  'undefi ...

  6. Python 简单web服务器的实现

    import re import socket def service_cilent(new_socket): request = new_socket.recv(1024).decode(" ...

  7. linux查看日志报错

    查看运行时错误: tail  -f  catalina.out   | grep   -C   10  'Exception'          10是行数: 单引号里面的是要查找的关键字:

  8. 低功耗蓝牙UUID三种格式转换

    熟悉BLE技术同学应该对UUID不陌生,服务.特征值.描述都是有UUID格式定义. 蓝牙广播中对服务UUID格式定义都有三种16 bit UUID.32 bit UUID.128 bit UUID. ...

  9. iOS音频学习笔记二:iOS SDK中与音频有关的相关框架

      上层:       Media Player Framework: 包含MPMoviePlayerController.MPMoviePlayerViewController.MPMusicPla ...

  10. 互联网项目中mysql推荐(读已提交RC)的事务隔离级别

    [原创]互联网项目中mysql应该选什么事务隔离级别 Mysql为什么不和Oracle一样使用RC,而用RR 使用RC的原因 这个是有历史原因的,当然要从我们的主从复制开始讲起了!主从复制,是基于什么 ...