多校1010 Taotao Picks Apples


思路:题解很有意思,适合线段树进阶
#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的更多相关文章
- 多校 1010 Taotao Picks Apples(补题)
>>点击进入原题<< 思路:题解很有意思,适合线段树进阶 考虑每次修改不叠加,因此我们可以从如何对原序列进行预处理着手.通过观察可以发现,将原序列从任意位置断开,我们可以通过分 ...
- 【杂题总汇】HDU-6406 Taotao Picks Apples
[HDU 6406]Taotao Picks Apples 多校赛的时候多写了一行代码就WA了……找了正解对拍,在比赛结束后17分钟AC了
- hdu 6406 Taotao Picks Apples 线段树 单点更新
Taotao Picks Apples Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Ot ...
- [乱搞]hdu 6406 Taotao picks apples 笛卡尔树+倍增
题目链接 Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n app ...
- hdu6406 Taotao Picks Apples(线段树)
Taotao Picks Apples 题目传送门 解题思路 建立一颗线段树,维护当前区间内的最大值maxx和可摘取的苹果数num.最大值很容易维护,主要是可摘取的苹果数怎么合并.合并左右孩子时,左孩 ...
- hdu 6406 Taotao Picks Apples (线段树)
Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n apples o ...
- 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到当前点被摘掉的桃子的 ...
- HDU 6406 Taotao Picks Apples & FJUT3592 做完其他题后才能做的题(线段树)题解
题意(FJUT翻译HDU): 钱陶陶家门前有一棵苹果树. 秋天来了,树上的n个苹果成熟了,淘淘会去采摘这些苹果. 到园子里摘苹果时,淘淘将这些苹果从第一个苹果扫到最后一个. 如果当前的苹果是第一个苹果 ...
- HDU 6406 Taotao Picks Apples 线段树维护
题意:给个T,T组数据: 每组给个n,m:n个数,m个操作: (对序列的操作是,一开始假设你手上东西是-INF,到i=1时拿起1,之后遍历,遇到比手头上的数量大的数时替换(拿到手的算拿走),问最后拿走 ...
随机推荐
- NOIP 2013 花匠 神仙操作
题目:https://www.luogu.org/problemnew/show/P1970 今天又学习了一个新的神仙操作: 标签是DP,想了一下,没什么心情写,默默打开题解——(狂喜!) 一位大佬( ...
- hive 内部表与外部表的区别
hive 内部表: hive> create table soyo55(name STRING,addr STRING,money STRING) row format delimited fi ...
- bzoj 1575: [Usaco2009 Jan]气象牛Baric【dp】
完了不会dp了 设f[i][j]为以i结尾,有j个时的最优值,辅助数组g[i][j]为s选了i和j,i~j中的误差值 转移是f[j][i]=min(f[k][i-1]+g[k][j]) #includ ...
- bzoj 1574: [Usaco2009 Jan]地震损坏Damage【dfs】
和March的那道不一样,只是非常单纯的带着贪心的dfs 首先一个点被隔断,与它相邻的所有点也会被隔断,打上删除标记,从1dfs即可 #include<iostream> #include ...
- ECMA里面的操作符,
ECMA里面的操作符,描述了一组操作于数据值的操作符,包括算数操作符.位操作符,关系操作符和相等操作符,ECMAscript操作符与之不同的是,他们能够使用于很多值,例如字符串.数字值.布尔值.甚至对 ...
- activiti遇到的问题
1.act_hi_detail表里面没有数据 原因是没有加历史变量的判断 2.流程图添加网关,写流转表达式 比如请假流程 大于3天小于5天的条件:${请假实体类.属性名称}
- Light 1289 - LCM from 1 to n (位图标记+素数筛选)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1289 题目描述: 给出一个n,求出lcm(1,2,3......n)为多少? ...
- C# 的占位符
static void Main(string[] args) { Console.WriteLine("A:{0},a:{1}",65,97); Console.ReadLine ...
- Git——github基本操作
基本概念 上一篇文章写到git共享仓库,但是有个局限性,就是这个仓库存在于本地,其他人无法从我们这个仓库拿到共享的内容 但是我们可以将这个共享仓库放入一个远程的服务器上,然后设置一些登录权限就能完美的 ...
- 如何让一个div里面的div垂直居中?
如何让一个div里面的div垂直居中? 如何让上面灰色有文字那个div和背景图标垂直居中,不管屏幕大小有好大,始终在垂直方向上的中间.上面有整个布局和样式表,谢谢高手指点 CSS3时代当然要用CSS3 ...