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 ( 1
n
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 [思路] 伸展树+打标记. 用伸展树维护这个序列,使得能 ...
随机推荐
- FreeCodeCamp初级算法部分学习
Reverse a String 翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串. 你的结果必须得是一个字符串 当你完成不了挑战的时候,记得开大招 ...
- C#RichTextBox复制并跳转指定行
方法一: rTxt.Focus(); //设置文本框中选定的文本起始点 为 指定行数第一个字符的索引 rTxt.SelectionStart = rTxt.GetFirstCharIndexFromL ...
- linux 源码包安装拾遗
源码包安装和apt-get/yum的区别 安装前的区别:概念上的区别 rpm和dpkg包是经过编译过的包,并且其安装位置由厂商说了算,厂商觉得安装在哪里合适,就会装在哪里,而源码包则是没有经过编译的文 ...
- [读书笔记] R语言实战 (一) R语言介绍
典型数据分析的步骤: R语言:为统计计算和绘图而生的语言和环境 数据分析:统计学,机器学习 R的使用 1. 区分大小写的解释型语言 2. R语句赋值:<- 3. R注释: # 4. 创建向量 c ...
- Maven下Flex国际化配置
之前写了flashbulid.initellij下的flex国际化配置,它们都是在本地打包发布的,那么我们的工程用maven管理了,需要自动发布.这时候如何修改flex的pom文件,来让它build的 ...
- jvm 虚拟机参数_栈内存分配
1.参数 -Xss 指定线程最大的栈空间,整个参数也直接决定了函数可调用的最大深度 2.测试代码 private static int count; public static void addCou ...
- ubuntu设置PATH
试了好多遍,多无效.. 最后在/etc/enviroment下设置才有效. 不过让有一些未解问题 我使用sudo su 进入到root用户权限,设置完成的. 重新使用sudo -s进入root用户权限 ...
- SQL SERVER-union
UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的每个 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每个 SELECT 语句中 ...
- STL_算法_对全部元素排序(sort、stable_sort)
C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) //大部分容器适用.不适用于list容器 sort(b,e) sort(b,e,p) stable_sort(b,e) ...
- Wordcount 和 shuffle的流程