》》点击进入原题《《

思路:题解很有意思,适合线段树进阶

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; #define lson l,m,o<<1
#define rson m+1,r,o<<1|1 const int maxn = 1e5 + ;
int a[maxn], d1[maxn], d2[maxn];
int tree[maxn << ], vis[maxn << ];
int ans, cur; void build(int l, int r, int o){
if (l == r){
tree[o] = a[l];
vis[o] = l;
return;
}
int m = (l + r) >> ;
build(lson);
build(rson);
tree[o] = max(tree[o << ], tree[o << | ]);
if (tree[o << ] >= tree[o << | ])
vis[o] = vis[o << ];
else vis[o] = vis[o << | ]; }
void query(int l, int r, int o, int ql, int qr, int k){
if (l == r){
if (tree[o]>k)
cur = min(cur, l);
return;
}
int m = (l + r) >> ;
if (l >= ql&&r <= qr){
if (tree[o << ] > k)
query(lson, ql, qr, k);
else if (tree[o << | ] > k)
query(rson, ql, qr, k);
return;
}
if (ql <= m)
query(lson, ql, qr, k);
if (qr > m)query(rson, ql, qr, k);
}
void query1(int l, int r, int o, int ql, int qr){
if (l >= ql&&r <= qr){
if (tree[o] > a[cur])
cur = vis[o];
return;
}
int m = (l + r) >> ;
if (ql <= m)query1(lson, ql, qr);
if (qr > m)query1(rson, ql, qr);
}
int main(){
ios::sync_with_stdio(false); int t; cin >> t;
while (t--){
int n, m, p, q, Max = ;
cin >> n >> m;
for (int i = ; i <= n; i++){
cin >> a[i];
if (a[i] > Max)
d1[i] = d1[i - ] + , Max = a[i];
else d1[i] = d1[i - ];
}
build(, n, );
for (int i = n; i; i--){
cur = n + ;
query(, n, , i, n, a[i]);
if (cur > n)cur = ;
d2[i] = d2[cur] + ;
}
while (m--){
cin >> p >> q;
ans = cur = ;
if (p != ){
query1(, n, , , p - );
}
ans += d1[cur];
if (q > a[cur])ans++;
else q = a[cur];
cur = n + ; if (p != n)query(, n, , p + , n, q);
if (cur <= n)ans += d2[cur];
cout << ans << endl;
}
}
}

多校1010 Taotao Picks Apples的更多相关文章

  1. 多校 1010 Taotao Picks Apples(补题)

    >>点击进入原题<< 思路:题解很有意思,适合线段树进阶 考虑每次修改不叠加,因此我们可以从如何对原序列进行预处理着手.通过观察可以发现,将原序列从任意位置断开,我们可以通过分 ...

  2. 【杂题总汇】HDU-6406 Taotao Picks Apples

    [HDU 6406]Taotao Picks Apples 多校赛的时候多写了一行代码就WA了……找了正解对拍,在比赛结束后17分钟AC了

  3. hdu 6406 Taotao Picks Apples 线段树 单点更新

    Taotao Picks Apples Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Ot ...

  4. [乱搞]hdu 6406 Taotao picks apples 笛卡尔树+倍增

    题目链接 Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n app ...

  5. hdu6406 Taotao Picks Apples(线段树)

    Taotao Picks Apples 题目传送门 解题思路 建立一颗线段树,维护当前区间内的最大值maxx和可摘取的苹果数num.最大值很容易维护,主要是可摘取的苹果数怎么合并.合并左右孩子时,左孩 ...

  6. hdu 6406 Taotao Picks Apples (线段树)

    Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n apples o ...

  7. hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...

  8. HDU 6406 Taotao Picks Apples & FJUT3592 做完其他题后才能做的题(线段树)题解

    题意(FJUT翻译HDU): 钱陶陶家门前有一棵苹果树. 秋天来了,树上的n个苹果成熟了,淘淘会去采摘这些苹果. 到园子里摘苹果时,淘淘将这些苹果从第一个苹果扫到最后一个. 如果当前的苹果是第一个苹果 ...

  9. HDU 6406 Taotao Picks Apples 线段树维护

    题意:给个T,T组数据: 每组给个n,m:n个数,m个操作: (对序列的操作是,一开始假设你手上东西是-INF,到i=1时拿起1,之后遍历,遇到比手头上的数量大的数时替换(拿到手的算拿走),问最后拿走 ...

随机推荐

  1. uva10828

    https://vjudge.net/problem/UVA-10828 裸高斯消元... 但是要判无解和无穷解. 当出现一个环时会无解,环上每个点只有一个出边. #include<bits/s ...

  2. ipvs和ipvsadm

    ipvs和ipvsadm ipvs:内核中的协议栈上实现 ipvs是LVS软件核心,是运行在LB上的,这是个基于ip层的负载均衡. ipvs的总体结构主要有ip包处理,负载均衡算法,系统配置和管理三个 ...

  3. 栗染-github中搭建博客遇到的问题之一

    运行命令:git push -u origin master To https://github.com/xuzhezhaozhao/Practice.git ! [rejected] master ...

  4. bzoj 1925: [Sdoi2010]地精部落【dp】

    设[f[i][j]为1到i,开头数字是j并且是山峰的方案数 注意到当数字j和j-1不相邻时,交换它们会得到一个新的符合要求的序列,所以f[i][j]+=f[i][j-1]; 如果相邻,那么j是山峰,j ...

  5. bzoj 1231: [Usaco2008 Nov]mixup2 混乱的奶牛【状压dp】

    设f[i][j]为奶牛选取状态为i,最后一头选的为j,转移直接f[k][(1<<(k-1)|i]+=f[j][i] #include<iostream> #include< ...

  6. SVN安装失败提示

    svnserve: error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: 1 ...

  7. 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  8. 转 js实践篇:例外处理Try{}catch(e){}

    程序开发中,编程人员经常要面对的是如何编写代码来响应错误事件的发生,即例外处理(exception handlers).如果例外处理代码设计得周全,那么最终呈现给用户的就将是一个友好的界面.否则,就会 ...

  9. C# 从服务器下载文件并保存到客户端

    参考代码: using System; using System.Net; namespace HT.SIHONG.Common.Utility { public class DownloadFile ...

  10. [译]Customizing Operations

    Customizing Operations定制操作 There is an ongoing development today where more and more protocols are b ...