》》点击进入原题《《

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

#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. 从csv文件读取数据到二维vector

    void ReadDataFromCsv(std::string &filename, std::vector<std::vector<std::string> > & ...

  2. bzoj1604

    treap+并查集 我们能想到一个点和最近点对连接,用并查集维护,但是这个不仅不能求,而且还是不对的,于是就看了题解 把距离转为A(x-y,x+y),这样两点之间的距离就是max(x'-X',y'-Y ...

  3. 17_activity任务栈和启动模式

    夜神安卓模拟器. 如果从第一个页面开启另外一个页面,只要不去调finish()方法咱们上一个页面它是不会退出的,它会留在底下.留在底下的话它设计了这样一个模式就是为了维护一个比较好的用户体验,你的仪器 ...

  4. bzoj 1492: [NOI2007]货币兑换Cash【贪心+斜率优化dp+cdq】

    参考:http://www.cnblogs.com/lidaxin/p/5240220.html 虽然splay会方便很多,但是懒得写,于是写了cdq 首先要想到贪心的思路,因为如果在某天买入是能得到 ...

  5. Akka源码分析-Cluster-Singleton

    akka Cluster基本实现原理已经分析过,其实它就是在remote基础上添加了gossip协议,同步各个节点信息,使集群内各节点能够识别.在Cluster中可能会有一个特殊的节点,叫做单例节点. ...

  6. jenkins手把手教你从入门到放弃02-jenkins在Windows系统安装与配置(详解)

    简介 上一篇对jenkins有了大致了解之后,那么我们就开始来安装一下jenkins. Jenkins安装 一.安装Java环境 1.你需要做的第一件事情就是在你的机器上安装Java环境.Jenkin ...

  7. 虚拟机安装cenos7后ifcfg看网卡无inet地址掩码等信息

    在虚拟机安装centos7,进入系统使用ifconfig命令时,只有lo网卡( 127.0.0.1的ip地址)和eno16777736网卡,而且此网卡没有inet地址.掩码等信息. 这时候查看/etc ...

  8. J - Ananagrams(map+vector)

    Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...

  9. WinForm ListBox 控件用法

    下面演示如何利用列表控件 ListBox 实现多选与移动选项: using IMS.WinFormClient.UserControls; using System; using System.Col ...

  10. 使用_CRTDBG_LEAK_CHECK_DF检查VC程序的内存泄漏(转)

    我们知道,MFC程序如果检测到存在内存泄漏,退出程序的时候会在调试窗口提醒内存泄漏.例如: class CMyApp : public CWinApp{public:BOOL InitApplicat ...