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≤st<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)的更多相关文章

  1. 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 ...

  2. 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を加算する. ...

  3. [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 ...

  4. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  5. 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 ...

  6. LeetCode Range Sum Query 2D - Mutable

    原题链接在这里:https://leetcode.com/problems/range-sum-query-2d-mutable/ 题目: Given a 2D matrix matrix, find ...

  7. 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 ...

  8. 308. Range Sum Query 2D - Mutable

    题目: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper ...

  9. [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 ...

随机推荐

  1. RoboGuice 3.0 (一)入坑篇

    RoboGuice是什么? 一个Android上的依赖注入框架. 依赖注入是什么? 从字面理解,这个框架做了两件事情,第一是去除依赖,第二是注入依赖.简单理解就是,将对象的初始化委托给一个容器控制器, ...

  2. javascript 常见方法记录

    1,trim():去除字符串左右两端的空格,在vbscript里面可以轻松地使用 trim.ltrim 或 rtrim,但在js中却没有这3个内置方法,需要手工编写. <script langu ...

  3. [css]我要用css画幅画(八) - Hello Kitty

    接着之前的[css]我要用css画幅画(七) - 哆啦A梦,这次画的是Hello Kitty. /* 开始前先说点废话, 一转眼就2016年了,过完年后一直没更新博客,无他,就是懒得动. 这一转眼,一 ...

  4. SqlServer--查询案例

    use  MyDataBase1 -- * 表示显示所有列 -- 查询语句没有加where条件表示查询所有行 select *from TblStudent ---只查询表中的部分列 select t ...

  5. MySQL查看数据库相关信息

    使用MySQL时,需要了解当前数据库的情况,例如当前的数据库大小.字符集.用户等等.下面总结了一些查看数据库相关信息的命令   1:查看显示所有数据库 mysql> show databases ...

  6. Linux make: g++: Command not found

    Linux使用make命令时遇到"make: g++: Command not found",这个主要是没有安装gcc-c++.x86_64,如下所示   [root@localh ...

  7. YourSQLDba 配置——修改备份路径

    公司一直使用YourSQLDba做本地备份,磁带机将本地备份文件上带做异地容灾备份.近期整理.验证备份时发现本地备份目录命名五花八门 其中有历史原因,也有无规划化的缘故,看着这些五花八门的目录,越看越 ...

  8. JVM之Class文件结构

    每一个class文件对应一个类或者接口,但是一个类或者接口不一定生成class文件,classloader直接生成. 8为字节为基础的二进制流,各个数据项按照严格的顺序排列在class文件中,没有任何 ...

  9. .NET应用架构设计—适当使用活动记录模式代替领域模型模式

    阅读目录: 1.背景介绍 2.简单介绍领域模型模式.活动记录模式 3.活动记录模式的简单示例及要点 4.总结 1.背景介绍 对软件开发方法论有兴趣的博友应该发现最近“领域驱动设计”慢慢的被人发现被人实 ...

  10. 设置DIV可编辑

    <div id="move" contentEditable="true">可编辑</div> 设置contentEditable属性可 ...