AC日记——Periodic RMQ Problem codeforces 803G
思路:
题目给一段序列,然后序列复制很多次;
维护序列很多次后的性质;
线段树动态开点;
来,上代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005 struct TreeNodeType {
int l, r, mid, min, flag; TreeNodeType *lc, *rc; TreeNodeType()
{
flag=;
lc = NULL;
rc = NULL;
}
};
struct TreeNodeType *root, *rot; int n, k, m; inline void in(int &now)
{
char Cget = getchar(); now = ;
while (Cget > '' || Cget < '') Cget = getchar();
while (Cget >= ''&&Cget <= '')
{
now = now * + Cget - '';
Cget = getchar();
}
} void tree_build_ori(TreeNodeType *&now, int l, int r)
{
if (now == NULL)
{
now = new TreeNodeType;
now->l = l, now->r = r;
now->mid = (l + r) >> ;
}
if (l == r)
{
in(now->min);
return;
}
tree_build_ori(now->lc, l, now->mid);
tree_build_ori(now->rc, now->mid + , r);
now->min = min(now->lc->min, now->rc->min);
} int tree_query_ori(TreeNodeType *&now, int l, int r)
{
if (now->l == l&&now->r == r) return now->min;
if (l > now->mid) return tree_query_ori(now->rc, l, r);
else if (r <= now->mid) return tree_query_ori(now->lc, l, r);
else return min(tree_query_ori(now->lc, l, now->mid), tree_query_ori(now->rc, now->mid + , r));
} inline void tree_down(TreeNodeType *&now)
{
now->lc->min = now->flag;
now->lc->flag = now->flag;
now->rc->min = now->flag;
now->rc->flag = now->flag;
now->flag = ;
} int solve(int l, int r)
{
if(r-l+>=n) return rot->min;
l%=n,r%=n;
if(l==) l=n;
if(r==) r=n;
if(r<l) return min(tree_query_ori(rot, l, n), tree_query_ori(rot, , r));
else return tree_query_ori(rot,l,r);
} void tree_change(TreeNodeType *&now, int l, int r, int x)
{
if (now->l == l&&now->r == r)
{
now->min = x;
now->flag = x;
return;
}
if (now->rc == NULL)
{
now->rc = new TreeNodeType;
now->rc->l = now->mid + ;
now->rc->r = now->r;
now->rc->mid = (now->rc->r + now->rc->l) >> ;
now->rc->min = solve(now->rc->l, now->rc->r);
}
if (now->lc == NULL)
{
now->lc = new TreeNodeType;
now->lc->l = now->l;
now->lc->r = now->mid;
now->lc->mid = (now->lc->l + now->lc->r) >> ;
now->lc->min = solve(now->lc->l, now->lc->r);
}
if (now->flag) tree_down(now);
if (l > now->mid) tree_change(now->rc, l, r, x);
else if (r <= now->mid) tree_change(now->lc, l, r, x);
else
{
tree_change(now->lc, l, now->mid, x);
tree_change(now->rc, now->mid + , r, x);
}
now->min = min(now->lc->min, now->rc->min);
} int tree_query(TreeNodeType *&now, int l, int r)
{
if (now->l == l&&now->r == r) return now->min;
if (now->rc == NULL)
{
now->rc = new TreeNodeType;
now->rc->l = now->mid + ;
now->rc->r = now->r;
now->rc->mid = (now->rc->r + now->rc->l) >> ;
now->rc->min = solve(now->rc->l, now->rc->r);
}
if (now->lc == NULL)
{
now->lc = new TreeNodeType;
now->lc->l = now->l;
now->lc->r = now->mid;
now->lc->mid = (now->lc->l + now->lc->r) >> ;
now->lc->min = solve(now->lc->l, now->lc->r);
}
if (now->flag) tree_down(now);
if (l > now->mid) return tree_query(now->rc, l, r);
else if (r <= now->mid) return tree_query(now->lc, l, r);
else return min(tree_query(now->lc, l, now->mid), tree_query(now->rc, now->mid + , r));
now->min = min(now->lc->min, now->rc->min);
} int main()
{
root = NULL, rot = NULL; int op, l, r, x;
in(n), in(k), tree_build_ori(rot, , n), in(m);
root = new TreeNodeType;
root->l = , root->r = n*k, root->mid = + n*k >> , root->min = rot->min;
for (; m--;)
{
in(op), in(l), in(r);
if (op == ) printf("%d\n", tree_query(root, l, r));
else in(x),tree_change(root, l, r, x);
}
return ;
}
AC日记——Periodic RMQ Problem codeforces 803G的更多相关文章
- (WAWAWAWAWAWAW) G. Periodic RMQ Problem
没有联通门 : Codeforces G. Periodic RMQ Problem /* Codeforces G. Periodic RMQ Problem MMP 什么动态开点线段树啊 ... ...
- codeforces 803G Periodic RMQ Problem
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...
- Codeforces 803G Periodic RMQ Problem 线段树
Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...
- Codeforces 803G Periodic RMQ Problem ST表+动态开节点线段树
思路: (我也不知道这是不是正解) ST表预处理出来原数列的两点之间的min 再搞一个动态开节点线段树 节点记录ans 和标记 lazy=-1 当前节点的ans可用 lazy=0 没被覆盖过 els ...
- Codeforces 803 G. Periodic RMQ Problem
题目链接:http://codeforces.com/problemset/problem/803/G 大致就是线段树动态开节点. 然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点 ...
- AC日记——C’s problem(c) TYVJ P4746 (清北学堂2017冬令营入学测试第三题)
P4746 C’s problem(c) 时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 题目描述 小C是一名数学家,由于它自制力比 ...
- AC日记——Sign on Fence Codeforces 484e
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- AC日记——Andryusha and Socks Codeforces 780a
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- AC日记——Sagheer, the Hausmeister codeforces 812b
812B - Sagheer, the Hausmeister 思路: 搜索: 代码: #include <cstdio> #include <cstring> #includ ...
随机推荐
- python 表格存取方法(转)
xlwt/xlrd库 存Excel文件:(如果存储数据中有字符,那么写法还有点小小的变化) import xlwt workbook = xlwt.Workbook(encoding='utf-8') ...
- URL地址传参中特殊符号的转码和解码
背景: URL传参在web开发中很常见,一般来说这种方式并不推荐,原因就是浏览器多种多样,各家浏览器对URL地址的解析的表现很不一样,特别是当参数有非ASCII字符.英文字母.阿拉伯数字时. 在CRM ...
- Tomcat详解及SNS系统的部署实现
Tomcat详解及SNS系统的部署实现 http://jungege.blog.51cto.com/4102814/1409290
- hasOne
public boolean hasOne(int n) { int lastdigit=0; while( n >0 ){ lastdigit=(n % 10); if(lastdigit== ...
- Caliburn Micro Binding KeyDown Event
<TextBox x:Name="MyTextBox" TextAlignment="Left" FontSize="10" Widt ...
- Where can I find the IPA logs
Retrieving the IPA logs will differ depending on which base image was used. Operating system that do ...
- c语言版贪吃蛇小游戏
编译环境:windows 7 64位 编译工具:codeblocks 13.12 备注:未使用graphics.h 声明:个人原创,未经允许,禁止转载!!! 数据结构:双向链表 1.程序未使用grap ...
- NVIDIA/DIGITS:Building DIGITS
在 Prerequisites中的 sudo apt-get update命令发生错误: W: GPG 错误:http://developer.download.nvidia.com/compute/ ...
- class内部处理
class A { public: int foo( ) { return val ; } static int staFun( ) { return staVal ; } static int st ...
- Java常用实体类
System类 访问系统属性 - 遍历 package org.zln.usefulclass.system; import java.util.Properties; /** * Created b ...