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. Java中的阻塞队列

    1. 什么是阻塞队列? 阻塞队列(BlockingQueue)是一个支持两个附加操作的队列.这两个附加的操作是:在队列为空时,获取元素的线程会等待队列变为非空.当队列满时,存储元素的线程会等待队列可用 ...

  2. Java暗箱操作之for-each

    对于我们常用的ArrayList等容器类,经常需要一个一个遍历里面的元素,从而对各个元素执行对应的操作. 像我代码写多了,通常的做法是用传统的,类似于数组遍历的方法,即在for循环中设置一个int变量 ...

  3. 微软CodeDom模型学习笔记(全)

    CodeDomProvider MSDN描述 CodeDomProvider可用于创建和检索代码生成器和代码编译器的实例.代码生成器可用于以特定的语言生成代码,而代码编译器可用于将代码编译为程序集. ...

  4. jQuery 3.0 的 setter/getter 模式

    jQuery 的 setter/getter 共用一个函数,通过是否传参来表明它是何种意义.简单说传参它是 setter,不传它是 getter. 一个函数具有多种意义在编程语言中并不罕见,比如函数重 ...

  5. java中设置代理的两种方式

    1 前言 有时候我们的程序中要提供可以使用代理访问网络,代理的方式包括http.https.ftp.socks代理.比如在IE浏览器设置代理. 那我们在我们的java程序中使用代理呢,有如下两种方式. ...

  6. IIS+域组策略+hosts:禁止访问指定网站

    一.简介 禁止访问网站可以通过多种方式实现,在网络设备上实现大概是性能最好的方式.本文在域服务器上实现该功能,优点是配置简单.可自定义跳转页面,缺点也很明显,遇到熟悉操作系统的用户,修改hosts文件 ...

  7. Chrome

    一.简介 二.安装 1)离线版 http://www.google.cn/chrome/browser/thankyou.html?statcb=1&platform=win64&st ...

  8. WPF系列 Path表示语法详解(Path之Data属性语法)

    示例: XAML(代码A): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...

  9. git stash 用法

    git stash用于将当前工作区的修改暂存起来,就像堆栈一样,可以随时将某一次缓存的修改再重新应用到当前工作区. 一旦用好了这个命令,会极大提高工作效率.   直接举例说明: 1.准备工作,首先初始 ...

  10. Web.xml中设置Servlet和Filter时的url-pattern匹配规则

    一.servlet容器对url的匹配过程: 当一个请求发送到servlet容器的时候,容器先会将请求的url减去当前应用上下文的路径作为servlet的映射url,比如我访问的是http://loca ...