Array Transformer

Time Limit: 5000ms
Memory Limit: 131072KB

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 (LRvp) 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 nmu ( 1n300, 000, 1m50, 000, 1u1, 000, 000, 000). Each of the next n lines contains an integer A[i] ( 1A[i]u). Each of the next m lines contains an instruction consisting of four integers LRvp ( 1LRn, 1vu, 1pn).

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的更多相关文章

  1. uva 12003 Array Transformer (线段树套平衡树)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. uva 12003 Array Transformer (大规模阵列)

    白皮书393页面. 乱搞了原始数组中.其实用另一种阵列块记录. 你不能改变原始数组. 请注意,与原来的阵列和阵列块的良好关系,稍微细心处理边境.这是不难. #include <cstdio> ...

  3. UVa 12003 Array Transformer (分块)

    题意:给定一个序列,然后有 m 个修改,问你最后的序列是什么,修改是这样的 l r v p 先算出从 l 到 r 这个区间内的 小于 v 的个数k,然后把第 p 个的值改成 k * u / (r - ...

  4. Array Transformer UVA - 12003

    题目:传送门 题意: 给你n个数,要进行m次操作 对于每次操作(l,r,v,p)代表:在区间[l,r]中有x(这个x是需要你自己找出来的)个数小于v,你需要把序列的第p个位置的值改成u∗k/(r−l ...

  5. UVA - 348Optimal Array Multiplication Sequence(递推)

    id=19208">题目:Optimal Array Multiplication Sequence 题目大意:给出N个矩阵相乘.求这些矩阵相乘乘法次数最少的顺序. 解题思路:矩阵相乘 ...

  6. uva 12003 分块

    大白上的原题,我就练练手... #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ; ll blo ...

  7. UVa 11922 - Permutation Transformer 伸展树

    第一棵伸展树,各种调试模板……TVT 对于 1 n 这种查询我处理的不太好,之前序列前后没有添加冗余节点,一直Runtime Error. 后来加上冗余节点之后又出了别的状况,因为多了 0 和 n+1 ...

  8. uva 11922 - Permutation Transformer

    splay的题: 学习白书上和网上的代码敲的: #include <cstdio> #include <cstring> #include <cstdlib> #i ...

  9. UVA 11922 Permutation Transformer(Splay Tree)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902 [思路] 伸展树+打标记. 用伸展树维护这个序列,使得能 ...

随机推荐

  1. [Atcoder Code Festival 2017 Qual A Problem D]Four Coloring

    题目大意:给一个\(n\times m\)的棋盘染四种颜色,要求曼哈顿距离为\\(d\\)的两个点颜色不同.解题思路:把棋盘旋转45°,则\((x,y)<-(x+y,x-y)\).这样就变成了以 ...

  2. [luogu3195 HNOI2008] 玩具装箱TOY (斜率优化dp)

    题目描述 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具, ...

  3. where和having

    where可以不能使用别名作为过滤条件,而having可以使用别名作为过滤条件. 在ORACLE中,select 语句的执行顺序是: 1. from语句 2. where语句(结合条件) 3. sta ...

  4. 【codeforces 738E】Subordinates

    [题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...

  5. Java基础学习总结(48)——Java 文档注释

    Java只是三种注释方式.前两种分别是// 和/* */,第三种被称作说明注释,它以/** 开始,以 */结束. 说明注释允许你在程序中嵌入关于程序的信息.你可以使用javadoc工具软件来生成信息, ...

  6. $.ajax() 获取不到return 返回值

    /*常见错误示例 直接在 ajax 里面return 结果 */ function demo(){ $.ajax({ url : 'test.do', type : "post", ...

  7. 浅析Mysql InnoDB存储引擎事务原理

    浅析Mysql InnoDB存储引擎事务原理 大神:http://blog.csdn.net/tangkund3218/article/details/47904021

  8. Edison Chou

    .NET中那些所谓的新语法之中的一个:自己主动属性.隐式类型.命名參数与自己主动初始化器 开篇:在日常的.NET开发学习中,我们往往会接触到一些较新的语法.它们相对曾经的老语法相比.做了非常多的改进, ...

  9. Swift开发教程--怎样使UITableViewController背景透明

    self.tableView.backgroundView? .backgroundColor = UIColor.clearColor(); self.tableView.backgroundCol ...

  10. Android Material Design-Getting Started(入门)-(一)

    转载请注明出处:http://blog.csdn.net/bbld_/article/details/40400343 翻译自:http://developer.android.com/trainin ...