嘟嘟嘟

带修改区间第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. 架构实战项目心得(四):使用Nexus配置Maven私有仓库

    一.安装配置Nexus 1.  下载nexus https://www.sonatype.com/download-oss-sonatype 2.  解压:tar -zxfnexus-3.5.2-01 ...

  2. easyui焦点离开事件的解决方案

  3. Expression Blend实例中文教程(1) - 开篇

    随着计算机软件开发分工细节化,微软对已有的产品线进行了调整,在保持原有经典开发工具Visual Studio基础上,又推出了一套新的设计开发工具系列,Expression Studio. Expres ...

  4. webservice随记

    WebService:跨平台.系统.跨语言间相互调用 CXF:Axis(Apache)-> Axis2(Apache)XFire -> CXF(Celtrix + XFire)(Apach ...

  5. [PHP] Oauth授权和本地加密

    1.Oauth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方 关键字:appKey appSecre ...

  6. Uva 1378 - A Funny Stone Game

    1378 - A Funny Stone Game Time limit: 3.000 seconds The funny stone game is coming. There are n pile ...

  7. VBA将指定Excel表数据批量生成到另一个Excel表中,每个sheet表一行数据

    Sub AutoInputValNewExcel() Dim sh1, sh2 As Worksheet Dim ws1, ws2 As Workbook ) ) ).Sheets() iRows = ...

  8. async await基本使用

    //——<ES6经典入门到进阶>牧码人-Strive 学习笔记//express示例 const fs = require('fs'); //简单封装 fs封装成一个promise con ...

  9. javascript时间格式转换(今天,昨天,前天)

    function transDate() { var $time =document.getElementById("share-time"); var date = $time. ...

  10. React Native之React速学教程(上)

    概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...