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 [思路] 伸展树+打标记. 用伸展树维护这个序列,使得能 ...
随机推荐
- d3基础图形模板笔记
散点图(scatter plot): http://bl.ocks.org/weiglemc/6185069 雷达图(radar): http://xgfe.github.io/uploads/che ...
- BZOJ 1009 [HNOI2008]GT考试 (KMP+矩阵乘法)
---恢复内容开始--- 题目大意:给定一个由数字构成的字符串A(len<=20),让你选择一个长度为n(n是给定的)字符串X,一个合法的字符串X被定义为,字符串X中不存在任何一段子串与A完全相 ...
- ios 人魔七七
http://www.cnblogs.com/qiqibo/category/533488.html
- [luogu] P4364 [九省联考2018]IIIDX(贪心)
P4364 [九省联考2018]IIIDX 题目背景 Osu 听过没?那是Konano 最喜欢的一款音乐游戏,而他的梦想就是有一天自己也能做个独特酷炫的音乐游戏.现在,他在世界知名游戏公司KONMAI ...
- Js原生实现抽奖功能
<div>代码 按钮代码 JS原生代码 完整的代码: <div style="width:365px;height:300px;border:2px solid gree ...
- 原生javaScript完成Ajax请求
使用原生javaScript完成Ajax请求,首先应该创建一个对象XMLHttprequest,考虑到兼容低版本IE浏览器,使用ActiveXObject对象,代码入下: var request; i ...
- Qt之qInstallMessageHandler(输出详细日志)
简述 安装之前已定义的消息处理程序,返回一个指向前一个消息处理程序. 消息处理程序是一个函数,用于打印调试信息.警告信息.严重错误和致命的错误的消息.Qt库(debug模式)包含成百上千的警告信息打印 ...
- 在对Activity基类的封装中,我做了什么
在开发实践中,不同Activity有很多代码是反复冗余的.因此非常有必要将这部分抽取出来.封装一个继承自Activity的类,命名为BaseActivity. 翻看之前写过的代码,起初,BaseAct ...
- Android之怎样改变焦点状态【EditText】
以EditText为例 1.改变焦点状态 password.setOnFocusChangeListener(new OnFocusChangeListener() { @Override publi ...
- sql server2008对字符串日期字段分区
近期对公司产品的日志数据库做了一个数据分区,数据库使用的是sql server 2008,这里给大家提供一个參考. 须要特别说明的是,非常多网上的样例分区字段都使用的是时间类型的.而这里因为时间字段原 ...