大白上的原题,我就练练手。。。

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

  1. UVa 12003 Array Transformer (分块)

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

  2. UVA 12003 Array Transformer

    Array Transformer Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Orig ...

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

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

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

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

  5. Array Transformer UVA - 12003

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

  6. UVA - 11754 Code Feat (分块+中国剩余定理)

    对于一个正整数N,给出C组限制条件,每组限制条件为N%X[i]∈{Y1,Y2,Y3,...,Yk[i]},求满足条件的前S小的N. 这道题很容易想到用中国剩余定理,然后用求第k小集合的方法输出答案.但 ...

  7. UVa 1640 (计数) The Counting Problem

    题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以 ...

  8. 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); } ...

  9. PHP搭建大文件切割分块上传功能

    背景 在网站开发中,文件上传是很常见的一个功能.相信很多人都会遇到这种情况,想传一个文件上去,然后网页提示"该文件过大".因为一般情况下,我们都需要对上传的文件大小做限制,防止出现 ...

随机推荐

  1. 【leetcode】Flatten Binary Tree to Linked List (middle)

    Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...

  2. 【linux】find删除指定时间之前的文件

    今天磁盘满了,想删掉一些老的日志文件.开始想写个python脚本,转念一想,可能shell脚本好点.结果发现,根本不用写脚本,一个find指令就可以解决问题了. 先上指令 -exec rm {} \; ...

  3. codeforces gym 100286 H - Hell on the Markets (贪心算法)

    题目链接 题意:n个数分别为a[i],问是否存在一组对应的b[i],b[i]=1 || b[i]=-1,使得ai*bi的n项和为0. 题解: 先证明一个结论吧,对于1≤ai≤i+1,前面ai个数一定可 ...

  4. Servlet题库

    一.    填空题 Servlet中使用Session对象的步骤为:调用  HttpServletRequest.getSession()  得到Session对象,查看Session对象,在会话中保 ...

  5. 解决Windows10下80端口被PID为4的System占用的问题

    一.背景 最近由于好奇心,更新了windows10系统,感觉上手还蛮快,而且体验还不错,但是在IDEA中做开发时,使用80端口进行启动项目的时候发现端口被占用了,于是尝试解决这个问题.具体步骤如下,分 ...

  6. SQL Server 查询时间段内数据

    方式一: ALTER Proc [dbo].[usp_Rpt_AcctTypeAudit] @FromDate datetime=null, -- yyyy-mm-dd (may change in ...

  7. Alcatraz安装在xcode7失败执行下面代码

    1.步奏rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin 2.步奏 rm ...

  8. 阿里云ecs Linux平台安装mongodb数据库

    MongoDB提供了linux平台上32位和64位的安装包,你可以在官网下载安装包. 下载地址:http://www.mongodb.org/downloads 下载完安装包,并解压 tgz(以下演示 ...

  9. 解决客户端访问https报错

    现象: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at com.sun.net.ssl. ...

  10. UISplitViewController - iPad分屏视图控制器

    UISplitViewController - 分屏视图控制器 概述 UISplitViewController 是一个容器vc, 展示一个 master-detail(主-详(从))界面. 主视图改 ...