整体二分(SP3946 K-th Number ZOJ 2112 Dynamic Rankings)
(/2和>>1不一样!!)
- #include <algorithm>
- #include <bitset>
- #include <complex>
- #include <deque>
- #include <exception>
- #include <fstream>
- #include <functional>
- #include <iomanip>
- #include <ios>
- #include <iosfwd>
- #include <iostream>
- #include <istream>
- #include <iterator>
- #include <limits>
- #include <list>
- #include <locale>
- #include <map>
- #include <memory>
- #include <new>
- #include <numeric>
- #include <ostream>
- #include <queue>
- #include <set>
- #include <sstream>
- #include <stack>
- #include <stdexcept>
- #include <streambuf>
- #include <string>
- #include <typeinfo>
- #include <utility>
- #include <valarray>
- #include <vector>
- #if __cplusplus >= 201103L
- #include <array>
- #include <atomic>
- #include <chrono>
- #include <condition_variable>
- #include <forward_list>
- #include <future>
- #include <initializer_list>
- #include <mutex>
- #include <random>
- #include <ratio>
- #include <regex>
- #include <scoped_allocator>
- #include <system_error>
- #include <thread>
- #include <tuple>
- #include <typeindex>
- #include <type_traits>
- #include <unordered_map>
- #include <unordered_set>
- #endif
- #define INF 1000000007
- #define MAXN 200010
- using namespace std;
- struct Node {
- int x,y,a,b,c;
- }q[MAXN],a[MAXN],b[MAXN];
- int t[MAXN],ans[MAXN],n,m,x,y,z,cnt,k;
- inline int read() {
- char ch;
- bool f=false;
- int res=0;
- while (((ch=getchar())<'0'||ch>'9')&&ch!='-');
- if (ch=='-')
- f=true;
- else
- res=ch-'0';
- while ((ch=getchar())>='0'&&ch<='9')
- res=(res<<3)+(res<<1)+ch-'0';
- return f?~res+1:res;
- }
- inline int lowbit(int x) {
- return x&(-x);
- }
- inline void add(int x,int y) {
- while (x<=n) {
- t[x]+=y,x+=lowbit(x);
- }
- }
- inline int sum(int x) {
- int summ=0;
- while (x>0) {
- summ+=t[x],x-=lowbit(x);
- }
- return summ;
- }
- inline void Build(int x,int i){
- cnt++;
- q[cnt].x=x,q[cnt].b=1,q[cnt].c=i;
- }
- inline void Build1(int x,int y,int k,int i){
- cnt++;
- q[cnt].x=x,q[cnt].y=y,q[cnt].a=k,q[cnt].b=2,q[cnt].c=i;
- }
- void sc(int t,int w,int l,int r) {
- if (t>=w)
- return;
- if (l==r) {
- for (int i=t;i<=w;++i)
- if (q[i].b==2)
- ans[q[i].c]=l;
- return;
- }
- int mid=(l+r)>>1,t1=0,w1=0;
- for (int i=t;i<=w;++i)
- if (q[i].b==1) {
- if (q[i].x<=mid)
- add(q[i].c,1),a[++t1]=q[i];
- else
- b[++w1]=q[i];
- }
- else {
- int tw=sum(q[i].y)-sum(q[i].x-1);
- if (tw>=q[i].a)
- a[++t1]=q[i];
- else {
- q[i].a=q[i].a-tw;
- b[++w1]=q[i];
- }
- }
- for (int i=1;i<=t1;++i)
- if (a[i].b==1)
- add(a[i].c,-1);
- for (int i=1;i<=t1;++i)
- q[t+i-1]=a[i];
- for (int i=1;i<=w1;++i)
- q[t+t1+i-1]=b[i];
- sc(t,t+t1-1,l,mid);
- sc(t+t1,w,mid+1,r);
- }
- int main() {
- n=read(),m=read();
- for (int i=1;i<=n;++i) {
- x=read();
- Build(x,i);
- }
- for (int i=1;i<=m;++i) {
- x=read(),y=read(),k=read();
- Build1(x,y,k,i);
- }
- sc(1,cnt,-INF,INF);
- for (int i=1;i<=m;++i)
- printf("%d\n",ans[i]);
- return 0;
- }
ZOJ 2112 Dynamic Rankings
- #include <algorithm>
- #include <bitset>
- #include <complex>
- #include<cstring>
- #include <deque>
- #include <exception>
- #include <fstream>
- #include <functional>
- #include <iomanip>
- #include <ios>
- #include <iosfwd>
- #include <iostream>
- #include <istream>
- #include <iterator>
- #include <limits>
- #include <list>
- #include <locale>
- #include <map>
- #include <memory>
- #include <new>
- #include <numeric>
- #include <ostream>
- #include <queue>
- #include <set>
- #include <sstream>
- #include <stack>
- #include <stdexcept>
- #include <streambuf>
- #include <string>
- #include <typeinfo>
- #include <utility>
- #include <valarray>
- #include <vector>
- #if __cplusplus >= 201103L
- #include <array>
- #include <atomic>
- #include <chrono>
- #include <condition_variable>
- #include <forward_list>
- #include <future>
- #include <initializer_list>
- #include <mutex>
- #include <random>
- #include <ratio>
- #include <regex>
- #include <scoped_allocator>
- #include <system_error>
- #include <thread>
- #include <tuple>
- #include <typeindex>
- #include <type_traits>
- #include <unordered_map>
- #include <unordered_set>
- #endif
- #define INF 1000000007
- #define MAXN 2000010
- using namespace std;
- struct Node {
- int x,y,a,b,c;
- }q[MAXN],a[MAXN],b[MAXN];
- int t[MAXN],ans[MAXN],n,m,x,y,z,cnt,k;
- int aa[MAXN];
- char ch;
- int ansn;
- inline int read() {
- char ch;
- bool f=false;
- int res=0;
- while (((ch=getchar())<'0'||ch>'9')&&ch!='-');
- if (ch=='-')
- f=true;
- else
- res=ch-'0';
- while ((ch=getchar())>='0'&&ch<='9')
- res=(res<<3)+(res<<1)+ch-'0';
- return f?~res+1:res;
- }
- inline int lowbit(int x) {
- return x&(-x);
- }
- inline void add(int x,int y) {
- while (x<=n) {
- t[x]+=y,x+=lowbit(x);
- }
- }
- inline int sum(int x) {
- int summ=0;
- while (x>0) {
- summ+=t[x],x-=lowbit(x);
- }
- return summ;
- }
- inline void Build(int x,int i) {
- cnt++;
- q[cnt].x=x,q[cnt].b=1,q[cnt].c=i;
- }
- inline void Build1(int x,int y,int k,int i) {
- cnt++,ansn++;
- q[cnt].x=x,q[cnt].y=y,q[cnt].a=k,q[cnt].b=0,q[cnt].c=ansn;
- }
- inline void Build2(int x,int y,int i) {
- cnt++;
- q[cnt].x=aa[x],q[cnt].b=-1,q[cnt].c=x;
- }
- inline void Build3(int x,int y,int i) {
- cnt++;
- q[cnt].x=aa[x],q[cnt].b=1,q[cnt].c=x;
- }
- void sc(int t,int w,int l,int r) {
- if (t>w)
- return;
- if (l==r) {
- for (int i=t;i<=w;++i)
- if (q[i].b==0)
- ans[q[i].c]=l;
- return;
- }
- int mid=(l+r)>>1,t1=0,w1=0;
- for (int i=t;i<=w;++i)
- if (q[i].b) {
- if (q[i].x<=mid)
- /*add(q[i].c,1),*/add(q[i].c,q[i].b),a[++t1]=q[i];
- else
- b[++w1]=q[i];
- }
- else {
- int tw=sum(q[i].y)-sum(q[i].x-1);
- if (tw>=q[i].a)
- a[++t1]=q[i];
- else {
- q[i].a=q[i].a-tw;
- b[++w1]=q[i];
- }
- }
- for (int i=1;i<=t1;++i)
- if (a[i].b)
- add(a[i].c,-a[i].b);
- for (int i=1;i<=t1;++i)
- q[t+i-1]=a[i];
- /*for (int i=1;i<=t1;++i)
- printf("%d %d %d %d %d ",a[i].x,a[i].y,a[i].a,a[i].b,a[i].c);
- printf("\n");*/
- for (int i=1;i<=w1;++i)
- q[t+t1+i-1]=b[i];
- sc(t,t+t1-1,l,mid);
- sc(t+t1,w,mid+1,r);
- }
- int main() {
- int T=read();
- while (T--){
- memset(q,0,sizeof q);
- memset(a,0,sizeof a);
- memset(b,0,sizeof b);
- memset(ans,0,sizeof ans);
- n=read(),m=read(),cnt=0,ansn=0;
- for (int i=1;i<=n;++i) {
- aa[i]=read();
- Build(aa[i],i);
- }
- for (int i=1;i<=m;++i) {
- /*scanf("%c",&ch);*/cin>>ch;x=read(),y=read();
- if (ch=='Q'){
- k=read();
- Build1(x,y,k,i);
- }
- else {
- Build2(x,y,i);
- aa[x]=y;
- Build3(x,y,i);
- }
- }
- //for (int i=1;i<=cnt;++i)
- // printf("%d %d %d %d %d\n",q[i].x,q[i].y,q[i].a,q[i].b,q[i].c);
- sc(1,cnt,-INF,INF);
- for (int i=1;i<=ansn;++i)
- printf("%d\n",ans[i]);
- }
- return 0;
- }
整体二分(SP3946 K-th Number ZOJ 2112 Dynamic Rankings)的更多相关文章
- 整体二分&cdq分治 ZOJ 2112 Dynamic Rankings
题目:单点更新查询区间第k大 按照主席树的思想,要主席树套树状数组.即按照每个节点建立主席树,然后利用树状数组的方法来更新维护前缀和.然而,这样的做法在实际中并不能AC,原因即卡空间. 因此我们采用一 ...
- 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )
在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...
- ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)
题目大意 给定一个数列,编号从 1 到 n,现在有 m 个操作,操作分两类: 1. 修改数列中某个位置的数的值为 val 2. 询问 [L, R] 这个区间中第 k 大的是多少 n<=50,00 ...
- ZOJ 2112 Dynamic Rankings(带修改的区间第K大,分块+二分搜索+二分答案)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- zoj 2112 Dynamic Rankings 动态第k大 线段树套Treap
Dynamic Rankings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ -2112 Dynamic Rankings 主席树 待修改的区间第K大
Dynamic Rankings 带修改的区间第K大其实就是先和静态区间第K大的操作一样.先建立一颗主席树, 然后再在树状数组的每一个节点开线段树(其实也是主席树,共用节点), 每次修改的时候都按照树 ...
- zoj 2112 Dynamic Rankings(主席树&动态第k大)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ 2112 Dynamic Rankings (动态第k大,树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
随机推荐
- 系统前端基本文件+ajax部分理解
静态页面: 一.static: css dist fonts images js model 二.templates: html ajax搜索操作: <html> <head> ...
- SQL Server非域(跨域)环境下镜像(Mirror)的搭建步骤及注意事项
在实际的生产环境下,我们经常需要跨域进行数据备份,而创建Mirror是其中一个方案.但跨域创建Mirror要相对复杂的多,需要借助证书进行搭建. 下面我们将具体的步骤总结如下: 第一部分 创建证书 S ...
- 网络编程 单纯UDP通信
网络编程 单纯UDP通信 1,UDP发送端 2,UDP接收端 UDP发送端: #include <stdio.h> #include <unistd.h> #include & ...
- 自动化测试之路3-selenium3+python3环境搭建
1.首先安装火狐浏览器 有单独文章分享怎么安装 2.搭建python环境 安装python,安装的时候把path选好,就不用自己在配置,安装方法有单独文档分享 安装好以后cmd打开输入python查 ...
- Django学习开发--笔记一(从零开始)
创建django项目注: 首先需在python中下载django 命令:pip install django1.任意文件中创建django项目 diango-admin startproject my ...
- SQLServer删除数据列
删除数据列 开发或者生产过程中多建.错误或者重复的数据列需要进行删除操作. 使用SSMS数据库管理工具删除数据列 方式一 1.打开数据库->选择数据表->展开数据表->展开数据列-& ...
- Python面试常见的问题
So if you are looking forward to a Python Interview, here are some most probable questions to be ask ...
- python3 Counter模块
from collections import Counter c = Counter("周周周周都方法及")print(c)print(type(c))print('__iter ...
- Set.js--创建无重复值的无序集合
Set 集合,不同于 Array,是一种没有重复值的集合. 以下代码出自于<JavaScript 权威指南(第六版)>P217,注意:这里并不是指 es6 / es2015 中的 Set ...
- iOS开发基础篇-transform属性
一. transform 属性 在OC中,通过 transform 属性可以修改对象的平移.缩放比例和旋转角度. 1)创建“基于控件初始位置”的形变 CGAffineTransformMakeRot ...