板子题

用的整体二分

唯一要注意的是别总手误打错变量

最近总犯这样sb错误,我佛了

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
const int inf=0x3f3f3f3f;
struct node{
	int op,x,y,z;
}q[3*N],lq[3*N],rq[3*N];
int n,m,t,a[N],c[N],ans[N],num;
void change(int x,int y){
	while(x<=n){
		c[x]+=y;
		x+=x&-x;
	}
}
int ask(int x){
	int y=0;
	while(x){
		y+=c[x];
		x-=x&-x;
	}
	return y;
}
void solve(int l,int r,int st,int ed){
	if(st>ed)return;
	if(l==r){
		for(int i=st;i<=ed;i++)
			if(q[i].op>0)ans[q[i].op]=l;
		return;
	}
	int mid=(l+r)>>1;
	int lt=0,rt=0;
	for(int i=st;i<=ed;i++){
		if(q[i].op<1){
			if(q[i].z<=mid)change(q[i].x,q[i].y),lq[++lt]=q[i];
			else rq[++rt]=q[i];
		}
		else {
			int cnt=ask(q[i].y)-ask(q[i].x-1);
			if(cnt>=q[i].z)lq[++lt]=q[i];
			else q[i].z-=cnt,rq[++rt]=q[i];
		}
	}
	for(int i=ed;i>=st;--i){
		if(q[i].op<1&&q[i].z<=mid)change(q[i].x,-q[i].y);
	}
	for(int i=1;i<=lt;i++)q[st+i-1]=lq[i];
	for(int i=1;i<=rt;i++)q[st+lt+i-1]=rq[i];
	solve(l,mid,st,st+lt-1);
	solve(mid+1,r,st+lt,ed);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		q[++t].op=0;
		q[t].x=i;
		q[t].z=a[i];
		q[t].y=1;
	}
	for(int i=1;i<=m;i++){
		char ch[2];
		int x,y;
		scanf("%s",ch);
		if(ch[0]=='C'){
			scanf("%d%d",&x,&y);
			q[++t].op=-1;
			q[t].x=x;
			q[t].z=a[x];
			q[t].y=-1;
			q[++t].op=0;
			q[t].x=x;
			q[t].z=y;
			q[t].y=1;
			a[x]=y;
		}
		else {
			scanf("%d%d%d",&q[t+1].x,&q[t+1].y,&q[t+1].z);
			q[++t].op=++num;
		}
	}
	solve(-10,10,1,t);
	for(int i=1;i<=num;i++) printf("%d\n",ans[i]);
	return 0;
}

  

Dynamic Rankings的更多相关文章

  1. BZOJ 1901: Zju2112 Dynamic Rankings[带修改的主席树]【学习笔记】

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7143  Solved: 2968[Su ...

  2. [bzoj1901][zoj2112][Dynamic Rankings] (整体二分+树状数组 or 动态开点线段树 or 主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  3. [BZOJ1901]Zju2112 Dynamic Rankings

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

  4. ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)

    题目大意 给定一个数列,编号从 1 到 n,现在有 m 个操作,操作分两类: 1. 修改数列中某个位置的数的值为 val 2. 询问 [L, R] 这个区间中第 k 大的是多少 n<=50,00 ...

  5. BZOJ-1901 Zju2112 Dynamic Rankings 函数式线段树 套 树状数组+离线处理

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MB Submit: 6058 Solved: 2521 [Su ...

  6. ZOJ 2112 Dynamic Rankings(主席树の动态kth)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 The Company Dynamic Rankings ...

  7. zoj 2112 Dynamic Rankings 动态第k大 线段树套Treap

    Dynamic Rankings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  8. Bzoj 1901: Zju2112 Dynamic Rankings 树套树,线段树,平衡树,Treap

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6471  Solved: 2697[Su ...

  9. Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6321  Solved: 2628[Su ...

  10. 【BZOJ-1901】Dynamic Rankings 带修主席树

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7292  Solved: 3038[Su ...

随机推荐

  1. Linux 下查看字体

    1.查看所有字体 命令:fc-list 2.查看中文字体 命令:fc-list :lang=zh 3.查看更多字体 命令:fc-match -v "AR PL UKai CN"

  2. 2018-2019-2 20175217 实验二《Java面向对象程序设计》实验报告

    一.实验报告封面 课程:Java程序设计 班级:1752班 姓名:吴一凡 学号:20175217 指导教师:娄嘉鹏 实验日期:2019年4月15日 实验时间:--- 实验序号:实验二 实验名称:Jav ...

  3. 【新特性速递】FineUIPro/Mvc/Core 全新移动端访问体验(示例首页)!

    移动端支持 虽然 FineUIPro 早在 2016 年就已经完成对移动端的适配工作,并新增了 50 多个官网示例. 并且,我们也新增了一个移动端的首页 http://pro.fineui.com/m ...

  4. ASP.NET Core 2.1 : 十五.图解路由(2.1 or earler)

    本文通过一张图来看一下路由的配置以及请求处理的机制.(ASP.NET Core 系列目录) 一.概述 路由主要有两个主要功能: 将请求的URL与已定义的路由进行匹配,找到该URL对应的处理程序并传入该 ...

  5. 详解WTL应用向导

    之前向 VS2019 中添加了 WTL 应用向导,今天来分析下该应用向导安装的相关文件,最终达到拷贝相关文件到 VS2019 的相应目录中即可直接使用 WTL 应用向导的目的. 在 VS2017 之前 ...

  6. NodeJs操作MongoDB之分页功能与常见问题

    NodeJs操作MongoDB之分页功能与常见问题 一,方法介绍 1,聚合操作之count count()方法可以查询统计符合条件的集合的总数 db.User.count(<query>) ...

  7. Django(五)母版继承、Cookie、视图装饰器等

    大纲 一.内容回顾 补充:默认值 补充:命名空间 二.模板语言 1.母版继承 2.include 3.自定义simple_tag 三.Cookie Cookie 使用总结 四.视图 1.获取用户请求相 ...

  8. springboot项目中配置swagger-ui

    Git官方地址:https://github.com/SpringForAll/spring-boot-starter-swagger Demo:https://github.com/dyc87112 ...

  9. xgboost 非官方每天编译

    xgboost  http://ssl.picnet.com.au/xgboost/ 非官方每天编译

  10. [ffmpeg] AVOption

    在ffmpeg中,常使用AVOption的API来进行参数设置.AVOption的API主要分为设置参数以及提取参数两种,无论是哪一种API都主要分为两大步骤: 寻找出参数所在的内存位置. 如果是设置 ...