题意

给定一个长度为n的数列,有m次询问,询问形如l r k

要你在区间[l,r]内选一个长度为k的区间,求区间最小数的最大值

Sol

二分答案

怎么判定,每种数字开一棵线段树

某个位置上的数大于等于它为1

那么就是求区间最大的1的序列长度大于k

二分的最优答案一定在这个区间内,否则不优

排序后就是用主席树优化空间

之前\(build\)一下,因为区间有长度不好赋值

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 5);
const int __(2e6 + 5); IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, m, tot, rt[_], a[_], id[_], ls[__], rs[__], o[_], len;
struct Data{
int maxl, maxr, maxn, len; IL void Init(){
maxl = maxr = maxn = len = 0;
}
} T[__], Ans; IL int Cmp(RG int x, RG int y){
return a[x] < a[y];
} IL Data Merge(RG Data A, RG Data B){
RG Data ret;
ret.maxl = A.maxl, ret.maxr = B.maxr, ret.len = A.len + B.len;
ret.maxn = max(A.maxr + B.maxl, max(A.maxn, B.maxn));
if(A.maxl == A.len) ret.maxl = A.len + B.maxl;
if(B.maxr == B.len) ret.maxr = B.len + A.maxr;
return ret;
} IL void Modify(RG int &x, RG int l, RG int r, RG int p){
ls[++tot] = ls[x], rs[tot] = rs[x], T[tot] = T[x], x = tot;
if(l == r){
T[x].maxl = T[x].maxr = T[x].maxn = 1;
return;
}
RG int mid = (l + r) >> 1;
if(p <= mid) Modify(ls[x], l, mid, p);
else Modify(rs[x], mid + 1, r, p);
T[x] = Merge(T[ls[x]], T[rs[x]]);
} IL void Query(RG int x, RG int l, RG int r, RG int L, RG int R){
if(L <= l && R >= r){
Ans = Merge(Ans, T[x]);
return;
}
RG int mid = (l + r) >> 1;
if(L <= mid) Query(ls[x], l, mid, L, R);
if(R > mid) Query(rs[x], mid + 1, r, L, R);
} IL void Build(RG int &x, RG int l, RG int r){
T[x = ++tot].len = r - l + 1;
if(l == r) return;
RG int mid = (l + r) >> 1;
Build(ls[x], l, mid), Build(rs[x], mid + 1, r);
} int main(RG int argc, RG char* argv[]){
n = Input();
for(RG int i = 1; i <= n; ++i) id[i] = i, o[i] = a[i] = Input();
sort(id + 1, id + n + 1, Cmp), sort(o + 1, o + n + 1);
len = unique(o + 1, o + n + 1) - o - 1;
Build(rt[len + 1], 1, n);
for(RG int i = len, j = n; i; --i){
rt[i] = rt[i + 1];
for(; j && a[id[j]] == o[i]; --j)
Modify(rt[i], 1, n, id[j]);
}
m = Input();
for(RG int i = 1; i <= m; ++i){
RG int l = Input(), r = Input(), k = Input();
RG int L = 1, R = len, ans = 0;
while(L <= R){
RG int mid = (L + R) >> 1;
Ans.Init();
Query(rt[mid], 1, n, l, r);
if(Ans.maxn >= k) ans = mid, L = mid + 1;
else R = mid - 1;
}
printf("%d\n", o[ans]);
}
return 0;
}

CF484E Sign on Fence的更多相关文章

  1. CF484E Sign on Fence && [国家集训队]middle

    CF484E Sign on Fence #include<bits/stdc++.h> #define RG register #define IL inline #define _ 1 ...

  2. 【CF484E】Sign on Fence(主席树)

    [CF484E]Sign on Fence(主席树) 题面 懒得贴CF了,你们自己都找得到 洛谷 题解 这不就是[TJOI&HEOI 排序]那题的套路吗... 二分一个答案,把大于答案的都变成 ...

  3. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  4. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  5. Codeforces 484E Sign on Fence(是持久的段树+二分法)

    题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...

  6. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  7. AC日记——Sign on Fence Codeforces 484e

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  8. 「CF484E」Sign on Fence「整体二分」「线段树」

    题意 给定一个长度为\(n\)的正整数序列,第\(i\)个数为\(h_i\),\(m\)个询问,每次询问\((l, r, w)\),为\([l, r]\)所有长度为\(w\)的子区间最小值的最大值.( ...

  9. (困难) CF 484E Sign on Fence,整体二分+线段树

    Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence o ...

随机推荐

  1. hiveql笔记(一)

    1.创建表 create table if not exists mydb.employees{ name String COMMENT 'Employee name', salary FLOAT C ...

  2. Visual Studio Code 调整字体大小

    { "editor.fontSize": 14, "window.zoomLevel": 1, } // 将设置放入此文件中以覆盖默认设置 { , , #代码字 ...

  3. 织梦默认编辑器 按下回车生成br标签改为生成p标签

    找到文件 \include\ckeditor\config.js 把 config.enterMode = CKEDITOR.ENTER_BR; config.shiftEnterMode = CKE ...

  4. c的文件流读取

    strtok(数组,分隔符); atof(数组)返回值为转换后的数字; fgets(数组指针,长度,文件句柄); 整整花了两天啊

  5. Nginx和php是怎么通信的?

    先来看一下搭建好PHP运行环境的Nginx配置文件. 非常重要的就是 fastcgi_pass 指令了,这个指令用于指定 fpm 进程监听的地址,Nginx 会把所有的 php 请求翻译成 fastc ...

  6. java url demo

    // File Name : URLDemo.java import java.net.*; import java.io.*; public class URLDemo { public stati ...

  7. C#中ASCII码学习心得

    1.利用调用ASCIIEncoding类来实现各种转换.如简单个ACS码和int转换. ***利用(int)ASCIIEncoding类对象.GetBytes(character)[0]得到整数: p ...

  8. HDU - 1430 魔板 (bfs预处理 + 康托)

    对于该题可以直接预处理初始状态[0, 1, 2, 3, 4, 5, 6, 7]所有可以到达的状态,保存到达的路径,直接打印答案即可. 关于此处的状态转换:假设有初始状态为2,3,4,5,0,6,7,1 ...

  9. 【spring-boot】spring aop 面向切面编程初接触

    众所周知,spring最核心的两个功能是aop和ioc,即面向切面,控制反转.这里我们探讨一下如何使用spring aop. 1.何为aop aop全称Aspect Oriented Programm ...

  10. 实时Web与WebSocket实践

    引言:实时Web越来越被重视,Google.Facebook等大公司也逐渐开始提供实时性服务.实时Web将是未来最热门的话题之一.  本文选自<基于MVC的JavaScript Web富应用开发 ...