uva 12003 分块
大白上的原题,我就练练手。。。 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + ;
const int SIZE = ;
ll block[N / SIZE + ][SIZE + ];
ll A[N]; int query(int L, int R, int v)
{
int k = ;
int lb = L / SIZE, rb = R / SIZE;
if(lb == rb) { for(int i = L; i <= R; ++i) if(A[i] < v) k++; }
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 change(int k, int u, int p, int L, int R)
{
ll x = (ll)u * k / (R - L + );
if(A[p] == x) return; int la = p / SIZE;
ll* B = &block[la][];
int pos = ;
ll old = A[p];
while(B[pos] < old) pos++;
A[p] = x; B[pos] = x;
if(x > old) {
while(pos < SIZE - && B[pos] > B[pos + ]) { swap(B[pos + ], B[pos]); pos++; }
}
else {
while(pos > && B[pos] < B[pos - ]) { swap(B[pos - ], B[pos]); pos--; }
}
}
int main()
{
int n, m, u;
while(~scanf("%d%d%d", &n, &m, &u))
{
int j = , k = ;
for(int i = ; i < n; ++i)
{
scanf("%lld", &A[i]);
block[k][j++] = A[i];
if(j == SIZE) { k++; j = ; }
}
for(int i = ; i < k; ++i) sort(block[i], block[i] + SIZE);
if(j) sort(block[k], block[k] + j);
int L, R, v, p;
while(m --)
{
int ans = ;
scanf("%d%d%d%d", &L, &R, &v, &p);
L--; R--; p--;
ans = query(L, R, v);
change(ans, u, p, L, R);
}
for(int i = ; i < n; ++i) printf("%lld\n", A[i]);
}
return ;
}
uva 12003 分块的更多相关文章
- UVa 12003 Array Transformer (分块)
题意:给定一个序列,然后有 m 个修改,问你最后的序列是什么,修改是这样的 l r v p 先算出从 l 到 r 这个区间内的 小于 v 的个数k,然后把第 p 个的值改成 k * u / (r - ...
- UVA 12003 Array Transformer
Array Transformer Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Orig ...
- 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> ...
- Array Transformer UVA - 12003
题目:传送门 题意: 给你n个数,要进行m次操作 对于每次操作(l,r,v,p)代表:在区间[l,r]中有x(这个x是需要你自己找出来的)个数小于v,你需要把序列的第p个位置的值改成u∗k/(r−l ...
- UVA - 11754 Code Feat (分块+中国剩余定理)
对于一个正整数N,给出C组限制条件,每组限制条件为N%X[i]∈{Y1,Y2,Y3,...,Yk[i]},求满足条件的前S小的N. 这道题很容易想到用中国剩余定理,然后用求第k小集合的方法输出答案.但 ...
- UVa 1640 (计数) The Counting Problem
题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以 ...
- UVa 11526 H(n)
题意: long long H(int n){ long long res = 0; for( int i = 1; i <= n; i=i+1 ){ res = (res + n/i); } ...
- PHP搭建大文件切割分块上传功能
背景 在网站开发中,文件上传是很常见的一个功能.相信很多人都会遇到这种情况,想传一个文件上去,然后网页提示"该文件过大".因为一般情况下,我们都需要对上传的文件大小做限制,防止出现 ...
随机推荐
- 【python】mysqlDB转xml中的编码问题
背景:有mysql数据库,将数据从数据库中读取,并存储到xml中 采用了MySQLdb和lxml两个库 具体编码处理过程如下: . 指定mysql的编码方式 .取数据库data->判断data类 ...
- python getopt.getopt 不能精确匹配的问题
代码:opts,argv = getopt.getopt(sys.argv[1:],('u:'),['ad','join','passwd=','domain=','dip=','test','ip= ...
- ios 宏定义 系统版本 判定
当需要判断iOS系统版本的时候,相信很多人都会这么干: #define SystemVersion [[UIDevice currentDevice] systemVersion].floatValu ...
- osgconv 批量转换
@echo offfor /f "delims=" %%i in ('dir/b *.osg') do ( "osgconv.exe" "%%~ni. ...
- LinkIssue: Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or cor
参考:http://blog.csdn.net/junjiehe/article/details/16888197 使用VisualStudio 编译链接中可能出现如下错误: LINK : fatal ...
- Cocoapods的使用教程
前言 对于iOS App的开发,几乎都采用了Cocoapods来管理第三方库,那么对于我们开发人员来说,这是必备技能,必须要掌握如何使用.这篇文章就是介绍如何安装和使用CocoaPods的. 这篇文章 ...
- JavaScript基础——使用数组
Array对象提供存储和处理一组其他对象的一种手段.数组可以存储数值.字符串或其他JavaScript对象.创建JavaScript数组有几种不同的方法.例如,下面的语句穿件同样的驻足的3个相同的版本 ...
- javascript事件与event对象的属性
javascript事件列表解说 事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown ...
- Linux下pipe使用注意事项
转自:http://blog.yufeng.info/archives/1485 Linux下的pipe使用非常广泛, shell本身就大量用pipe来粘合生产者和消费者的. 我们的服务器程序通常会用 ...
- git 使用技巧
让git不检测文件权限 在android根目录执行:repo forall -c git config core.filemode false即可 修改默认编辑器: git config –globa ...