hdu5412CRB and Queries
动态修改求区间K大。
整体二分是一个神奇的东西: http://www.cnblogs.com/zig-zag/archive/2013/04/18/3027707.html
入门:
一般的主席树都挂了,而且又难写。
南神的分析:http://blog.csdn.net/hdu2014/article/details/47834431 ORZ
然后对着板子写了一份:
1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cmath>
5 #include<cstring>
6 #define maxn 450000
7 #define inf 2000000000
8 typedef long long ll;
9
10 using namespace std;
11 struct query
12 {
13 int x,y,k,s,tp,cur;
14 }q[maxn],q1[maxn],q2[maxn];
15 int a[maxn],ans[maxn],tmp[maxn],t[maxn];
16 int n,m,num,cnt;
17
18 void add(int x,int y)
19 {
20 for (int i=x;i<=n;i+=i&(-i)) t[i]+=y;
21 }
22 int ask(int x)
23 {
24 int s=;
25 for (int i=x;i>;i-=i&(-i)) s+=t[i];
26 return s;
27 }
28
29 void divide(int head,int tail,int l,int r)
30 {
31 if (head>tail) return;
32 if (l==r)
33 {
34 for (int i=head;i<=tail;i++)
35 if (q[i].tp==) ans[q[i].s]=l;
36 return;
37 }
38 int mid=(l+r)>>;
39 for (int i=head;i<=tail;i++)
40 {
41 if (q[i].tp==&&q[i].y<=mid) add(q[i].x,);
42 else
43 if (q[i].tp==&&q[i].y<=mid) add(q[i].x,-);
44 else
45 if (q[i].tp==) tmp[i]=ask(q[i].y)-ask(q[i].x-);
46 }
47
48 for (int i=head;i<=tail;i++)
49 {
50 if (q[i].tp==&&q[i].y<=mid) add(q[i].x,-);
51 else
52 if (q[i].tp==&&q[i].y<=mid) add(q[i].x,);
53 }
54
55 int l1,l2;
56 l1=l2=;
57 for (int i=head;i<=tail;i++)
58 if (q[i].tp==)
59 {
60 if (q[i].cur+tmp[i]>q[i].k-) q1[++l1]=q[i];
61 else
62 {
63 q[i].cur+=tmp[i];
64 q2[++l2]=q[i];
65 }
66 }
67 else
68 {
69 if (q[i].y<=mid) q1[++l1]=q[i];
70 else q2[++l2]=q[i];
71 }
72
73 for (int i=;i<=l1;i++) q[head+i-]=q1[i];
74 for (int i=;i<=l2;i++) q[head+i+l1-]=q2[i];
75 divide(head,head+l1-,l,mid);
76 divide(head+l1,tail,mid+,r);
77 }
78
79 int main()
80 {
81 while (scanf("%d",&n)!=EOF)
82 {
83 for (int i=;i<=n;i++) t[i]=;
84 memset(q,,sizeof(q));
85 memset(q1,,sizeof(q1));
86 memset(q2,,sizeof(q2));
87
88 num=cnt=;
89 for (int i=;i<=n;i++)
90 {
91 scanf("%d",&a[i]);
92 q[++num].x=i,q[num].y=a[i];
93 q[num].tp=;q[num].s=;
94 }
95 int ss,x,y,z;
96 scanf("%d",&m);
97 for (int i=;i<=m;i++)
98 {
99 scanf("%d",&ss);
if (ss==)
{
scanf("%d%d%d",&x,&y,&z);
q[++num].x=x,q[num].y=y,q[num].k=z;
q[num].tp=;q[num].s=++cnt;
}
else
{
scanf("%d%d",&x,&y);
q[++num].x=x;
q[num].y=a[x];
q[num].tp=;q[num].s=;
q[++num].x=x,q[num].y=y;
q[num].tp=,q[num].s=;
a[x]=y;
}
}
divide(,num,,inf);
for (int i=;i<=cnt;i++)
printf("%d\n",ans[i]);
}
return ;
123 }
2s左右。
hdu5412CRB and Queries的更多相关文章
- 实践 HTML5 的 CSS3 Media Queries
先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...
- CSS3 Media Queries 实现响应式设计
在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...
- 使用CSS3 Media Queries实现网页自适应
原文来源:http://webdesignerwall.com 翻译:http://xinyo.org 当今银屏分辨率从 320px (iPhone)到 2560px (大屏显示器)或者更大.人们也不 ...
- SQL Queries from Transactional Plugin Pipeline
Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability to quickly query yo ...
- Media Queries 详解
Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码: <link href="css/reset.css" rel ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- SPOJ GSS1 Can you answer these queries I[线段树]
Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A q ...
- 【Codeforces710F】String Set Queries (强制在线)AC自动机 + 二进制分组
F. String Set Queries time limit per test:3 seconds memory limit per test:768 megabytes input:standa ...
随机推荐
- bootstrap历练实例:按钮作为输入框组前缀或后缀
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Bootstrap 响应式表格
响应式表格 通过把任意的 .table 包在 .table-responsive class 内,您可以让表格水平滚动以适应小型设备(小于 768px).当在大于 768px 宽的大型设备上查看时,您 ...
- ios UITableViewCell重用问题
在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用 ...
- 用xtrabackup实现mysql的主从复制 阿里云rds到自己创建mysql
来源 http://blog.51cto.com/825536458/1803968参考https://segmentfault.com/a/1190000003063874 如果我们用传统的mysq ...
- percona-server-5.7二进制安装(tokudb)
1.下载二进制安装包(适用于红帽.centos) https://www.percona.com/downloads/Percona-Server-LATEST/Percona-Server-5.7. ...
- 玩转ApplicationContextAware
当一个类实现了这个接口之后,这个类就可以方便地获得 ApplicationContext 中的所有bean.换句话说,就是这个类可以直接获取Spring配置文件中,所有有引用到的bean对象.结合工厂 ...
- verilog behavioral modeling --procedural assignments
1.procedural assignments are used for updating reg ,integer , time ,real,realtime and memory data ty ...
- '>>' should be '> >' within a nested template argument list
在编译关于opencv相机标定的工程的时候出现了这个问题 vector<vector<Point3f>> objectPoints; error: 'objectPoint ...
- centos中python2替换为python3,并解决yum出错
这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...
- myeclipse 改变模版
一.修改Servlet的默认模板代码 使用MyEclipse创建Servlet时,根据默认的Servlet模板生成的Servlet代码如下: 1 package gacl.servlet.study; ...