UVA 12003 Array Transformer
Array Transformer
This problem will be judged on UVA. Original ID: 12003
64-bit integer IO format: %lld Java class name: Main
Write a program to transform an array A[1], A[2],..., A[n] according to m instructions. Each instruction (L, R, v, p) means: First, calculate how many numbers from A[L] to A[R](inclusive) are strictly less than v, call this answer k. Then, change the value of A[p] to u*k/(R - L + 1), here we use integer division (i.e. ignoring fractional part).
Input
The first line of input contains three integer n, m, u ( 1n
300, 000, 1
m
50, 000, 1
u
1, 000, 000, 000). Each of the next n lines contains an integer A[i] ( 1
A[i]
u). Each of the next m lines contains an instruction consisting of four integers L, R, v, p ( 1
L
R
n, 1
v
u, 1
p
n).
Output
Print n lines, one for each integer, the final array.
Sample Input
10 1 11
1
2
3
4
5
6
7
8
9
10
2 8 6 10
Sample Output
1
2
3
4
5
6
7
8
9
6
Explanation: There is only one instruction: L = 2, R = 8, v = 6, p = 10. There are 4 numbers (2,3,4,5) less than 6, so k = 4. The new number in A[10] is 11*4/(8 - 2 + 1) = 44/7 = 6.
解题:分块
参考lrj同学的那本大白
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = + ;
const int SIZE = ;
int n,m,u,A[maxn],block[maxn/SIZE+][SIZE];
void init() {
scanf("%d%d%d",&n,&m,&u);
int b = ,j = ;
for(int i = ; i < n; ++i) {
scanf("%d",A+i);
block[b][j] = A[i];
if(++j == SIZE) {
b++;
j = ;
}
}
for(int i = ; i < b; ++i)
sort(block[i],block[i] + SIZE);
if(j) sort(block[b],block[b]+j);
}
int query(int L,int R,int v) {
int lb = L/SIZE,rb = R/SIZE,k = ;
if(lb == rb) {
for(int i = L; i <= R; ++i)
k += (A[i] < v);
} else {
for(int i = L; i < (lb+)*SIZE; ++i)
if(A[i] < v) ++k;
for(int i = rb*SIZE; i <= R; ++i)
if(A[i] < v) ++k;
for(int i = lb+; i < rb; ++i)
k += lower_bound(block[i],block[i]+SIZE,v) - block[i];
}
return k;
}
void update(int p,int x) {
if(A[p] == x) return;
int old = A[p],pos = ,*B = &block[p/SIZE][];
A[p] = x;
while(B[pos] < old) ++pos;
B[pos] = x;
while(pos < SIZE- && B[pos] > B[pos + ]) {
swap(B[pos],B[pos+]);
++pos;
}
while(pos > && B[pos] < B[pos - ]) {
swap(B[pos],B[pos-]);
--pos;
}
}
int main() {
init();
while(m--) {
int L,R,v,p;
scanf("%d%d%d%d",&L,&R,&v,&p);
--L;
--R;
--p;
int k = query(L,R,v);
update(p,(LL)u*k/(R - L + ));
}
for(int i = ; i < n; ++i)
printf("%d\n",A[i]);
return ;
}
UVA 12003 Array Transformer的更多相关文章
- uva 12003 Array Transformer (线段树套平衡树)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 12003 Array Transformer (大规模阵列)
白皮书393页面. 乱搞了原始数组中.其实用另一种阵列块记录. 你不能改变原始数组. 请注意,与原来的阵列和阵列块的良好关系,稍微细心处理边境.这是不难. #include <cstdio> ...
- UVa 12003 Array Transformer (分块)
题意:给定一个序列,然后有 m 个修改,问你最后的序列是什么,修改是这样的 l r v p 先算出从 l 到 r 这个区间内的 小于 v 的个数k,然后把第 p 个的值改成 k * u / (r - ...
- Array Transformer UVA - 12003
题目:传送门 题意: 给你n个数,要进行m次操作 对于每次操作(l,r,v,p)代表:在区间[l,r]中有x(这个x是需要你自己找出来的)个数小于v,你需要把序列的第p个位置的值改成u∗k/(r−l ...
- UVA - 348Optimal Array Multiplication Sequence(递推)
id=19208">题目:Optimal Array Multiplication Sequence 题目大意:给出N个矩阵相乘.求这些矩阵相乘乘法次数最少的顺序. 解题思路:矩阵相乘 ...
- uva 12003 分块
大白上的原题,我就练练手... #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ; ll blo ...
- UVa 11922 - Permutation Transformer 伸展树
第一棵伸展树,各种调试模板……TVT 对于 1 n 这种查询我处理的不太好,之前序列前后没有添加冗余节点,一直Runtime Error. 后来加上冗余节点之后又出了别的状况,因为多了 0 和 n+1 ...
- uva 11922 - Permutation Transformer
splay的题: 学习白书上和网上的代码敲的: #include <cstdio> #include <cstring> #include <cstdlib> #i ...
- UVA 11922 Permutation Transformer(Splay Tree)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902 [思路] 伸展树+打标记. 用伸展树维护这个序列,使得能 ...
随机推荐
- phpstorm中,光标变成一个长方红色块,如何调回来?
今天使用phpstorm,不知道碰到了什么,光标变成长方红色块(如图),搞半天终于调回来了,变回了细细的竖线,记录一下: 其实按一下insert键就可以了
- done
- 从YV12到NV12
Media SDK的decoder,vpp,encoder对输入输出格式有着严格的限制,现在仅仅支持NV12.那么如何从其他格式转化为NV12是日常工作中经常遇到的事情.本篇文章以此为目的,讨论如何将 ...
- MyBatis学习总结(18)——MyBatis与Hibernate区别
也用了这么久的Hibernate和MyBatis了,一直打算做一个总结,就他们之间的优缺点说说我自己的理解: 首先,Hibernate是一个ORM的持久层框架,它使用对象和我们的数据库建立关系,在Hi ...
- 关于android的设备管理器-DevicePolicyManager(一)
在Andorid的设置->安全里面有个设备管理器的选项,相信大部分android用户都不太会去注意这个东西.近期在安装了一个应用之后发现这个里面的东西变了.怎么回事呢,研究研究看看.</s ...
- Hibernate中session回话的get方法和load方法的区别
1.报错方式不同: 前提:获取的数据不存在 get方法会报异常:空指针异常 load方法会报异常:对象为找到异常,给定值没有行存在. 2.load方法 这种方式总是会返回一个代理而不是真正得去查询数据 ...
- php扩展之 pdo_mysql.so
总结:新搭编译安装的 nginx+php+mysql环境,执行之前开发的项目遇到了没有安装pdo的问题 1.进入到php5的源代码包里面,ext以下.找到pdo_mysql目录 首先运行:/usr/l ...
- spring web mvc第一天
spring web mvc 感觉就是高大上啊!啥都是配置文件就能够了.所以第一步就是弄清楚配置文件使用和总体框架的流程! Spring web mvc最重要的当然是Controller,也就是首先 ...
- python设计模式 之 简单工厂模式
简单工厂模式属于类的创建型模式,适合用来对大量具有共同接口的类进行实例化,它能够推迟到执行的时候才动态决定要创建哪个类的实例.而不是在编译时就必须知道要实例化哪个类. python: #!/usr/b ...
- android drawable资源调用使用心得
1. 调用顺序 android 调用应用图片资源时,会优先选择当前手机屏幕dpi对应的的文件夹(如drawable-ldpi, drawable-mdpi, drawable-hdpi, drawab ...