嘟嘟嘟

带修改区间第k大。

然而某谷把数据扩大到了1e5,所以用分块现在只能得50分。

分块怎么做呢?很暴力的。

基本思想还是块内有序,块外暴力统计。

对于修改,直接重排修改的数所在块,时间复杂度O(√nlogn√n)。

对于询问,二分答案,然后在每个块内再二分统计小于mid的数有几个,块外暴力统计,时间复杂度O(m * log1e9 * √nlog√n),所以只能过1e4。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e5 + ;
const int maxb = ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << ) + (ans << ) + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, q, a[maxn];
char c[]; int S, Cnt = , blo[maxn], lb[maxn], rb[maxn];
int b[maxb][maxb];
void init()
{
S = sqrt(n);
Cnt = n % S ? n / S + : n / S;
for(rg int i = ; i <= Cnt; ++i) lb[i] = rb[i - ] + , rb[i] = lb[i] + S - ;
rb[Cnt] = n;
for(rg int i = , j = ; i <= n; ++i) blo[i] = j, j += (i == rb[j]);
for(rg int i = , cb = ; i <= Cnt; ++i, cb = )
{
for(rg int j = lb[i]; j <= rb[i]; ++j) b[i][++cb] = a[j];
sort(b[i] + , b[i] + cb + );
}
}
inline void update(const int& x, const int& k)
{
a[x] = k;
int t = blo[x], cb = ;
for(rg int i = lb[t]; i <= rb[t]; ++i) b[t][++cb] = a[i];
sort(b[t] + , b[t] + cb + );
}
inline int judge(const int& L, const int& R, const int& x, const int& k)
{
int l = blo[L], r = blo[R], ret = ;
if(l == r)
{
for(rg int i = L; i <= R; ++i) ret += (a[i] < x);
return ret < k;
}
for(rg int i = l + ; i < r; ++i)
{
int tp = lower_bound(b[i] + , b[i] + rb[i] - lb[i] + , x) - b[i] - ;
if(tp < ) tp = ;
if(tp > rb[i] - lb[i]) tp = rb[i] - lb[i] + ;
ret += tp;
}
for(rg int i = L; i <= rb[l]; ++i) ret += (a[i] < x);
for(rg int i = lb[r]; i <= R; ++i) ret += (a[i] < x);
return ret < k;
} int main()
{
n = read(), q = read();
for(rg int i = ; i <= n; ++i) a[i] = read();
init();
for(rg int i = ; i <= q; ++i)
{
scanf("%s", c);
if(c[] == 'C')
{
int x = read(), y = read();
update(x, y);
}
else
{
int L = read(), R = read(), k = read();
int l = , r = 1e9;
while(l < r)
{
int mid = (l + r + ) >> ;
if(judge(L, R, mid, k)) l = mid;
else r = mid - ;
}
write(l), enter;
}
}
return ;
}

luogu P2617 Dynamic Rankings(分块,n <= 1e4)的更多相关文章

  1. luogu P2617 Dynamic Rankings && bzoj 1901 (带修改区间第k大)

    链接:https://www.luogu.org/problemnew/show/P2617 思路: 如果直接在主席树上修改的话,每次修改都会对后面所有的树造成影响,一次修改的复杂度就会变成 : n* ...

  2. Luogu P2617 Dynamic Rankings

    带修主席树的模板,因为状态不好所以敲了很长时间,不过写完感觉能更好地理解主席树了. 核心其实就是树状数组套主席树,维护方法不再是以前的那种一步一修改,而是对于树状数组上的每一个点建立一棵权值线段树,然 ...

  3. luogu P2617 Dynamic Rankings(主席树)

    嘟嘟嘟 一句话题意:带修改区间第\(k\)小. 不修改都会,主席树板子.但是有修改就要比较深入的理解主席树了. 众所周知,主席树中以\(i\)为根的线段树维护的是\([1, i]\)这个前缀的权值,因 ...

  4. Luogu P2617 Dynamic Rankings(整体二分)

    题目 动态区间第K小模板题. 一个非常可行的办法是BIT套动态开点权值SegTree,但是它跑的实在太慢了. 然后由于这题并没有强制在线,所以我们可以使用整体二分来吊打树套树. 当然如果强制在线的话就 ...

  5. LUOGU P2617 Dynamic Rankings(树状数组套主席树)

    传送门 解题思路 动态区间第\(k\)大,树状数组套主席树模板.树状数组的每个位置的意思的是每棵主席树的根,维护的是一个前缀和.然后询问的时候\(log\)个点一起做前缀和,一起移动.时空复杂度\(O ...

  6. [luogu P2617] Dynamic Rankings 带修主席树

    带修改的主席树,其实这种,已经不能算作主席树了,因为这个没有维护可持久化的... 主席树直接带修改的话,由于这种数据结构是可持久化的,那么要相应改动,这个节点以后所有的主席树,这样单次修改,就达到n* ...

  7. P2617 Dynamic Rankings(树状数组套主席树)

    P2617 Dynamic Rankings 单点修改,区间查询第k大 当然是无脑树套树了~ 树状数组套主席树就好辣 #include<iostream> #include<cstd ...

  8. 2018.07.01洛谷P2617 Dynamic Rankings(带修主席树)

    P2617 Dynamic Rankings 题目描述 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i ...

  9. 洛谷P2617 Dynamic Rankings (主席树)

    洛谷P2617 Dynamic Rankings 题目描述 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a ...

随机推荐

  1. https Java SSLException protocol_version的问题解决方法

    我们的业务代码里有需要用爬虫爬取商品的图片地址,然后在转到我们的服务器里的过程,中间当然少不了下载图片的过程,最近目标网站有些改变,就是之前http前缀的图片地址部分改成了https,然后就造成了一个 ...

  2. ngnix优化【转】

    nginx的优化 1. gzip压缩优化 2. expires缓存有还 3. 网络IO事件模型优化 4. 隐藏软件名称和版本号 5. 防盗链优化 6. 禁止恶意域名解析 7. 禁止通过IP地址访问网站 ...

  3. java.lang.UnsupportedClassVersionError: action/Login : Unsupported major.minor version 52.0 (unable to load class action.Login)异常

    用myeclipse新建一个web项目,用了struts2框架,tomcat启动的时候报了这个错误. 我的问题原因是tomcat7的运行环境不知道为什么设置成了myeclipse1.7的jre,我给它 ...

  4. Codis3.2 安装部署

    转载请注明出处:https://www.cnblogs.com/format-ch/p/9323841.html 一.软件下载 下载 下载 zookeeper (Codis注册中心) http://m ...

  5. CSS3自定义loading效果

    效果: 使用CSS3完成loading的制作 css样式: <style type="text/css"> .mask { position: fixed; left: ...

  6. 爬取地图列表并下载-node.js

    var fs = require('fs'); var request = require('request'); var cheerio = require('cheerio'); var url ...

  7. csharp:.net 3.5 using System.Runtime.Serialization.Json read json

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. 软件项目技术点(7)——在canvas上绘制自定义图形

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 图形种类 目前我们软件可以绘制出来的形状有如下这几种,作为开发者我们一直想支持用户可以拖拽的类似word里面图形库,但目前还没有找到比 ...

  9. PHP discuz模板语法

    Discuz! X 模板的解析主要是 ./source/class/class_template.php 文件解析处理的,如果需要深入了解请可以看看这个文件! 模板嵌套语法 将被嵌套模板内容解析为 P ...

  10. ubuntu18.04安装谷歌浏览器

    sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/ wget -q ...