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. iOS--UICollectionView(滚动视图)入门

     UICollectionView @interface UICollectionView : UIScrollView   UICollectionView 和UICollectionViewCon ...

  2. 从tabBarController的一个item上的控制器跳转到另一个item上的控制器

    先从习惯性的tabBarController开始,很多应用的外框都是用这个开始的,而从tabBarController的一个item上的控制器跳转到另一个上的,往往都是直接通过点击tabBar上的不同 ...

  3. CentOS 6.5 安装 MySQL5.6 并用Navicat for MySQL 连接

    环境 : MySQL 5.6.21 64位 CentOS 6.5 64位 VMware 10 Navicat for MySQL 11 1.卸载自带mysql [root@localhost  ~]# ...

  4. Linux 使用fdisk添加新分区

    Linux系统由于数据累计增长.前期存储规划不合理等诸多因素,出现存储不够用的情况时,此时就需要扩展逻辑分区或添加新的逻辑分区.下面介绍一下通过使用fdsik添加新的逻辑分区. 首先使用df命令检查文 ...

  5. mybatis 动态sql表达式相关应用

    一.mybatis 表达式简介 对于mybatis3 ,提供了一种动态sql的方式.通过动态sql我们可以直接在mybatis 的xm映射文件中直接通过条件判断的方式进行查询添加的拼接.mybatis ...

  6. Genymotion的安装与eclipse配置教程

    第一部分安装Genymotion和VirtualBox虚拟机 1,Genymotion模拟器可以在官网下载,但是下载前需要注册账号,账号注册后登陆,点击Download. 2,选择第一个with Vi ...

  7. Centos7 and docker practices

    1. Failed to get D-Bus connection: Operation not permitted error when you execute the systemctl star ...

  8. 学习大神笔记之“MyBatis学习总结(二)”

    MyBatis对表的增删改查操作         主要有两种方式:基于XML实现和基于注解实现. 完整项目结构: 工具类:MyBatisUtil-------用于获取  sqlsession pack ...

  9. java设计模式之备忘录模式

    备忘录模式 备忘录模式是一种软件设计模式:在不破坏封闭的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态.一听到备忘录这个字的时候想起了小小时打的游 ...

  10. Bootstrap CSS 表单

    表单布局 Bootstrap 提供了下列类型的表单布局: 垂直表单(默认) 内联表单 水平表单 垂直或基本表单 基本的表单结构是 Bootstrap 自带的,个别的表单控件自动接收一些全局样式.下面列 ...