AOJ DSL_2_D Range Update Query (RUQ)
Range Update Query
数列 A = {a0,a1 ,...,an−1} に対し、次の2つの操作を行うプログラムを作成せよ。
- update(s,t,x): as,as+1,...,at をxに変更する。
- find(i): ai の値を出力する。
ただし、ai (i=0,1,...,n−1)は、231-1で初期化されているものとする。
入力
n q
query1
query2
:
queryq
1行目にAの要素数n, クエリの数qが与えられる。続くq行にi 番目のクエリ queryi が与えられる。queryi は以下のいずれかの形式で与えられる。
0 s t x
または
1 i
各クエリの最初の数字は、クエリの種類を示し、'0'がupdate(s,t,x)、'1'がfind(i) を表す。
出力
各findクエリについて、値を1行に出力せよ。
制約
- 1≤n≤100000
- 1≤q≤100000
- 0≤s≤t<n
- 0≤i<n
- 0≤x<231−1
入力例 1
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
出力例 1
1
3
入力例 2
1 3
1 0
0 0 0 5
1 0
出力例 2
2147483647
5
区间修改,单点查询,线段树+tag标记。压了压常数,继续打榜。
#include <cstdio>
#include <cstdlib>
#include <cstring> #define siz 10000000 char buf[siz], *bit = buf; inline int nextInt(void) {
register int ret = ;
register int neg = false; for (; *bit < ''; ++bit)
if (*bit == '-')neg ^= true; for (; *bit >= ''; ++bit)
ret = ret * + *bit - ''; return neg ? -ret : ret;
} #define inf 2147483647 int n, m; int tag[]; int find(int t, int l, int r, int p) {
if (~tag[t])
return tag[t];
int mid = (l + r) >> ;
if (p <= mid)
return find(t << , l, mid, p);
else
return find(t << | , mid + , r, p);
} void update(int t, int l, int r, int x, int y, int k) {
if (l == x && r == y)
tag[t] = k;
else {
int mid = (l + r) >> ;
if (~tag[t])
tag[t << ] = tag[t << | ] = tag[t], tag[t] = -;
if (y <= mid)
update(t << , l, mid, x, y, k);
else if (x > mid)
update(t << | , mid + , r, x, y, k);
else {
update(t << , l, mid, x, mid, k);
update(t << | , mid + , r, mid + , y, k);
}
}
} signed main(void) {
fread(buf, , siz, stdin); n = nextInt();
m = nextInt(); for (int i = ; i < (n << ); ++i)
tag[i] = inf; for (int i = ; i <= m; ++i) {
int c = nextInt();
if (c) // find(x)
printf("%d\n", find(, , n, nextInt() + ));
else {
int x = nextInt();
int y = nextInt();
int k = nextInt();
update(, , n, x + , y + , k);
}
} //system("pause");
}
@Author: YouSiki
AOJ DSL_2_D Range Update Query (RUQ)的更多相关文章
- AOJ DSL_2_A Range Minimum Query (RMQ)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0,a1,...,an−1} with the ...
- AOJ DSL_2_E Range Add Query (RAQ)
Range Add Query 数列 A = {a1,a2,...,an} に対し.次の2つの操作を行うプログラムを作成せよ. add(s,t,x): as,as+1,...,at にxを加算する. ...
- [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- Range Sum Query 2D - Mutable & Immutable
Range Sum Query 2D - Mutable Given a 2D matrix matrix, find the sum of the elements inside the recta ...
- LeetCode Range Sum Query 2D - Mutable
原题链接在这里:https://leetcode.com/problems/range-sum-query-2d-mutable/ 题目: Given a 2D matrix matrix, find ...
- Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- 308. Range Sum Query 2D - Mutable
题目: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper ...
- [Locked] Range Sum Query 2D - Mutable
Range Sum Query 2D - Mutable Given a 2D matrix matrix, find the sum of the elements inside the recta ...
随机推荐
- web.xml中监听器配置
<!-- 监听器的配置:监听器配置完以后,应用系统在启动的时候就会开启这些监听器. 监听器的理解:监听器好比一个卫兵,卫兵一直站在那里等待长官的命令,当卫兵收到长官的命令以后,立即执行 之前已经 ...
- 基于Windows 10平台的PM2.5检测器制作
本篇文章详细讲解了如何利用SDS011激光式PM2.5传感器.HC-06蓝牙模块和Windows 10设备完成一个简单的PM2.5检测器及其应用程序的开发.该检测器使用蓝牙完成数据输出,方便设备连接, ...
- ORA-02292: integrity constraint (xxxx) violated - child record found
在更新表的主键字段或DELETE数据时,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 这个是因为主外 ...
- 使用强大的可视化工具redislive来监控我们的redis,别让自己死的太惨~~~
作为玩windows的码农,在centos上面装点东西,真的会崩溃的要死,,,我想大家也知道,在centos上面,你下载的是各种源代码,需要自己编译...而 使用yum的话,这个吊软件包有点想nuge ...
- SQL周、日、月、年数据统计
本文只是记录在项目中用到的统计的SQL语句,记一笔以防忘了 /// <summary> /// 获取统计数据 /// </summary> /// <param name ...
- python基础(八)面向对象的基本概念
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 谢谢逆水寒龙,topmad和Liqing纠错 Python使用类(class)和对 ...
- 基础SQL语句/语法
SQL是现在进入互联网工作人们的必须技能之一,下面分享自己觉得很nice的SQL基本语句,从网上找了,觉得很不错,就分享给大家!简要介绍基础语句: 1.说明:创建数据库 Create DATABAS ...
- Mybatis(综合案例)
MyBatis本是apache的一个开源项目iBatis,2010年这个项目有Apache software foundation 迁移到了Google code,并改名MyBatis.2013年11 ...
- visualstudio 2013 mysql entityframeword :实体模型无法添加,闪退
发现电脑中安装的mysql-connector-net,版本为6.9.8 1.卸载此版本 2.重新安装mysql-connector-net 6.8.3 3.注意web.config中版本 4.注意项 ...
- ZooKeeper 笔记(1) 安装部署及hello world
先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html Get ...