【题目分析】

外层区间线段树,内层是动态开点的权值线段树。

SY神犇说树套树注重的是内外层的数据结构的选择问题,果然很重要啊。

动态开点的实现方法很好。

【代码】

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath> #include <set>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue> using namespace std; #define mlog 16
#define inf (0x3f3f3f3f) unsigned Getunsigned()
{
unsigned x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f; } #define maxn 50005
#define F(i,j,k) for (unsigned i=j;i<=k;++i)
#define maxm maxn<<8 unsigned rt[maxn<<2],n,m,sum[maxm],le[maxm],ri[maxm],lazy[maxm];
unsigned c,L,R,cnt,opt; void push(unsigned &o,unsigned l,unsigned r)
{
if (!o) o=++cnt;
if (L<=l&&r<=R)
{
lazy[o]++;
sum[o]+=(r-l+1);
return;
}
unsigned mid=l+r>>1;
if (L<=mid) push(le[o],l,mid);
if (R>mid) push(ri[o],mid+1,r);
sum[o]=sum[le[o]]+sum[ri[o]]+lazy[o]*(r-l+1);
} void modi(unsigned o,unsigned l,unsigned r)
{
push(rt[o],1,n); if (l==r) return ;
unsigned mid=l+r>>1;
if (c<=mid) modi(o<<1,l,mid);
else modi(o<<1|1,mid+1,r);
} unsigned calc(unsigned o,unsigned l,unsigned r)
{
if (!o) return 0;
if (L<=l&&r<=R) return sum[o];
unsigned mid=l+r>>1,tmp=0;
if (L<=mid) tmp+=calc(le[o],l,mid);
if (R>mid) tmp+=calc(ri[o],mid+1,r);
return tmp+lazy[o]*(min(R,r)-max(L,l)+1);
} unsigned ask(unsigned o,unsigned l,unsigned r)
{
if (l==r) return l;
unsigned mid=l+r>>1,tmp=calc(rt[o<<1],1,n);
if (c<=tmp) return ask(o<<1,l,mid);
c-=tmp; return ask(o<<1|1,mid+1,r);
} int main()
{
n=Getunsigned();
m=Getunsigned();
F(i,1,m)
{
opt=Getunsigned(); L=Getunsigned();
R=Getunsigned(); c=Getunsigned();
if (opt==1) c=n-c+1,modi(1,1,n);
else printf("%u\n",n-ask(1,1,n)+1);
}
return 0;
}

BZOJ 3110 [Zjoi2013]K大数查询 ——树套树的更多相关文章

  1. BZOJ.3110.[ZJOI2013]K大数查询(整体二分 树状数组/线段树)

    题目链接 BZOJ 洛谷 整体二分求的是第K小(利用树状数组).求第K大可以转为求第\(n-K+1\)小,但是这样好像得求一个\(n\). 注意到所有数的绝对值\(\leq N\),将所有数的大小关系 ...

  2. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  3. 树套树专题——bzoj 3110: [Zjoi2013] K大数查询 &amp; 3236 [Ahoi2013] 作业 题解

    [原题1] 3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MB Submit: 978  Solved: 476 Descri ...

  4. bzoj 3110: [Zjoi2013]K大数查询 树状数组套线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1384  Solved: 629[Submit][Stat ...

  5. BZOJ 3110: [Zjoi2013]K大数查询( 树状数组套主席树 )

    BIT+(可持久化)权值线段树, 用到了BIT的差分技巧. 时间复杂度O(Nlog^2(N)) ---------------------------------------------------- ...

  6. BZOJ 3110([Zjoi2013]K大数查询-区间第k大[段修改,在线]-树状数组套函数式线段树)

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec   Memory Limit: 512 MB Submit: 418   Solved: 235 [ Submit][ ...

  7. BZOJ 3110 [Zjoi2013]K大数查询(整体二分)

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 11654  Solved: 3505[Submit][St ...

  8. bzoj 3110 [Zjoi2013]K大数查询【树套树||整体二分】

    树套树: 约等于是个暴力了.以区间线段树的方式开一棵权值线段树,在权值线段树的每一个点上以动态开点的方式开一棵区间线段树. 结果非常惨烈(时限20s) #include<iostream> ...

  9. BZOJ 3110: [Zjoi2013]K大数查询 [整体二分]

    有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是多少. N ...

随机推荐

  1. 2017“编程之美”终章:AI之战勇者为王

    编者按:8月15日,第六届微软“编程之美”挑战赛在选手的火热比拼中圆满落下帷幕.“编程之美”挑战赛是由微软主办,面向高校学生开展的大型编程比赛.自2012年起,微软每年都在革新比赛命题.紧跟时代潮流, ...

  2. ycsb安装和使用介绍

    nosql性能测试工具ycsb0.1的使用 使用文档参考地址:https://www.cnblogs.com/SailorXiao/p/5808828.html ycsb地址:https://gith ...

  3. 快速生成导入亿级测试数据到sqlserver

    如果采用insert into 循环一条一条插入速度比较慢 可以先将数据插入临时表,然后在临时表数据量到达批量插入的行数时执行例如:目标表 (col1,col2,col3) --根据目标表结构复制一个 ...

  4. 使用javap深入理解Java整型常量和整型变量的区别

    我下图代码第五行和第九行分别定义了一个整型变量和一个整型常量: static final int number1 = 512; static int number3 = 545; Java程序员都知道 ...

  5. VC-基础:隐藏不安全函数的warning-_CRT_SECURE_NO_WARNINGS

    >tmp.cpp(): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strc ...

  6. Spring对注解(Annotation)处理【转】

    1.从Spring2.0以后的版本中,spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...

  7. PWN题搭建

    0x00.准备题目 例如:level.c #include <stdio.h> #include <unistd.h> int main(){ char buffer[0x10 ...

  8. Authentication token manipulation error报错解决办法

    Authentication token manipulation error报错解决办法 #参考http://blog.163.com/junwu_lb/blog/static/1916798920 ...

  9. 二. python函数与模块

    第四章.内置函数与装饰器详解 1.内置函数补充1 注:红色圆圈:必会:  紫红色方框:熟练:   绿色:了解 callable() 判断函数是否可以被调用执行 def f1(): pass f1() ...

  10. 智能指针之 weak_ptr

    1. weak_ptr 介绍 std::weak_ptr 是一种智能指针,它对被 std::shared_ptr 管理的对象存在非拥有性("弱")引用.在访问所引用的对象指针前必须 ...