题目:传送门

题意:

给你n个数,要进行m次操作

对于每次操作(l,r,v,p)代表:在区间[l,r]中有x(这个x是需要你自己找出来的)个数小于v,你需要把序列的第p个位置的值改成u∗k/(r−l + 1)

最后输出序列就完了

题解:

因为他要找出来区间中有多少数小于v,所以我们就要维护一个数组a,在这个a数组里面要放置每一块排序后的结束(我的代码是从小到大排序)。为什么要排序,因为对于一个序列排完序之后我们可以通过二分找出来小于v的那个数的位置,然后我们又知道每一个块的左区间位置和右区间位置,所以可以很简单求出来x的值

具体操作见代码:

  1 #include <iostream>
2 #include<stdio.h>
3 #include<string.h>
4 #include<algorithm>
5 #include<math.h>
6 using namespace std;
7 const int maxn=300005;
8 int a[maxn],L[maxn],R[maxn],belong[maxn],b[maxn];
9 int l,r,v,p,n,m,u;
10 void build()
11 {
12 int len=sqrt(n);
13 int ci=n/len;
14 for(int i=1; i<=ci; ++i)
15 {
16 L[i]=len*(i-1)+1;
17 R[i]=len*i;
18 }
19 R[ci]=n;
20
21 for(int i=1; i<=ci; ++i)
22 {
23 for(int j=L[i]; j<=R[i]; ++j)
24 {
25 belong[j]=i;
26 }
27 sort(a+L[i],a+R[i]+1);
28 }
29 }
30 int query()
31 {
32 int ans=0;
33 if(belong[l]==belong[r])
34 {
35 for(int i=l; i<=r; ++i)
36 {
37 if(b[i]<v) ans++;
38 }
39 }
40 else
41 {
42 for(int i=l; i<=R[belong[l]]; i++) ans+=b[i]<v;
43 for(int i=belong[l]+1; i<belong[r]; i++)
44 ans+=lower_bound(a+L[i],a+R[i]+1,v)-a-L[i];
45 for(int i=L[belong[r]]; i<=r; i++) ans+=b[i]<v;
46 }
47 return ans;
48 }
49 void update(int x)
50 {
51 int pos=lower_bound(a+L[belong[p]],a+R[belong[p]]+1,b[p])-a;
52 x=(long long)u*x/(r-l+1);
53 a[pos]=x;
54 if(b[p]>x)
55 {
56
57 for(int i=pos; i>L[belong[p]]; i--)
58 {
59 if(a[i]<a[i-1]) swap(a[i],a[i-1]);
60 else break;
61 }
62 }
63 else if(b[p]<x)
64 {
65
66 for(int i=pos; i<R[belong[p]]; i++)
67 {
68 if(a[i]>a[i+1]) swap(a[i],a[i+1]);
69 else break;
70 }
71 }
72 b[p]=x;
73 }
74 int main()
75 {
76
77 while(~scanf("%d%d%d",&n,&m,&u))
78 {
79 for(int i=1; i<=n; ++i)
80 scanf("%d",&a[i]),b[i]=a[i];
81 build();
82 while(m--)
83 {
84 scanf("%d%d%d%d",&l,&r,&v,&p);
85 update(query());
86 }
87 for(int i=1; i<=n; ++i)
88 {
89 printf("%d\n",b[i]);
90 }
91 }
92 return 0;
93 }
94 /*
95 10 1 11
96 1
97 2
98 3
99 4
100 5
101 6
102 7
103 8
104 9
105 10
106 2 8 6 10
107 */

Array Transformer UVA - 12003的更多相关文章

  1. UVA 12003 Array Transformer

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

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

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

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

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

  4. UVa 12003 Array Transformer (分块)

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

  5. uva 12003 分块

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

  6. 题解【UVA12003】Array Transformer

    题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例#1 10 1 11 1 2 3 4 5 6 7 8 9 10 2 8 6 10 输出样例#1 1 2 3 4 5 6 7 8 9 6 ...

  7. Spark Mllib框架1

    1. 概述 1.1 功能 MLlib是Spark的机器学习(machine learing)库,其目标是使得机器学习的使用更加方便和简单,其具有如下功能: ML算法:常用的学习算法,包括分类.回归.聚 ...

  8. Spark MLlib框架详解

    1. 概述 1.1 功能 MLlib是Spark的机器学习(machine learing)库,其目标是使得机器学习的使用更加方便和简单,其具有如下功能: ML算法:常用的学习算法,包括分类.回归.聚 ...

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

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

随机推荐

  1. SpringSecurity应用篇

    前面吹水原理吹了一篇幅了,现在讲解下应用篇幅,前面说过,如果要用SpringSecurity的话要先导入一个包 <dependency> <groupId>org.spring ...

  2. 关于 percona monitoring plugins插件报slave is stoped on ip地址

    思路:肯定是某个item触发了触发器 去看触发器,找到 slave is stoped,如下图 看到键是mysql.running-slave ,然后去定义key的文件中查看该键对应的脚本,修改脚本. ...

  3. 通过show status 命令了解各种sql的执行频率

    show status like 'Com_%'; Com_select                | 1   执行select操作的次数,一次查询只累加1 Com_insert         ...

  4. [WPF] 在单元测试中使用 Prism 的 EventAggregator,订阅到 ThreadOption.UIThread 会报错

    1. 问题 [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { ContainerLocator ...

  5. IE浏览器直接在页面中显示7z文件而不是下载问题解决

    IE浏览器中输入7z文件的完整下载URL后,不是保存文件,而是直接在页面中显示(当然是乱码) 这是因为浏览器对不同的资源文件处理的方式不同,例如图片文件,一般会直接打开,所以我们可以不用7z,使用zi ...

  6. SAP 修改表和表中数据

    平时修改表中数据的方式有一下几种: 1.一般就是通过SE11或者是SE16进去,找到那条记录,然后将模式变成EDIT,然后修改保存. 2.通过SQL语句在程序中实现数据库表的修改操作 3.通过SE16 ...

  7. 对象存储 COS 帮您轻松搞定跨域访问需求

    背景 早期为了避免 CSRF(跨站请求伪造) 攻击,浏览器引入了 "同源策略" 机制.如果两个 URL 的协议,主机名(域名/IP),端口号一致,则视为这两个 URL " ...

  8. IDEA 简介

    什么是IDEA IDEA 全称 IntelliJ IDEA,是 Java 语言开发的集成环境,IntelliJ 在业界被公认为最好的 Java 开发工具之一,尤其在智能代码助手.代码自动提示.重构.J ...

  9. Go Code Review Comments

    Go Code Review Comments https://golang.org/wiki/CodeReviewComments

  10. python RecursionError: maximum recursion depth exceeded while calling

    import copyimport sys # 导入sys模块sys.setrecursionlimit(8192) # 将默认的递归深度修改为r = sys.getrecursionlimit()_ ...