多校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,之后遍历,遇到比手头上的数量大的数时替换(拿到手的算拿走),问最后拿走 ...
随机推荐
- bzoj 4883 棋盘上的守卫 —— 基环树转化
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4883 首先,注意到每个点可横可竖,但花费一样: 所以考虑行列的交集,那么这个条件可以转化为行 ...
- Ural 1382 2SAT
ural1382 直接套用 2SAT模板 缩点 拓扑排序... #include<iostream> #include<cstdio> #include<cstdlib& ...
- Could not find modernizr-2.6.2 in any of the sources
- python之类的继承及方法讲解分析
#!/usr/bin/env python#-*- conding:utf-8 -*- # class Person(object):# def __init__(self,name,age):# s ...
- 洛谷P5055 【模板】可持久化文艺平衡树(FHQ Treap)
题面 传送门 题解 日常敲板子.jpg //minamoto #include<bits/stdc++.h> #define R register #define inline __inl ...
- Bryce1010 Acm模板
目录 STL标准模板库 STL简介 STL pair STL set STL vector STL string STL stack STL queue STL map upper_bound和low ...
- pyCharm最新激活码(2018)
1.修改hosts文件: 添加下面一行到hosts文件,目的是屏蔽掉Pycharm对激活码的验证 0.0.0.0 account.jetbrains.com windwos系统hosts文件路径为:C ...
- JD笔试
题目表述: 给定n道题目,以及每道题目答对的概率,问小明能及格的概率. 样例: 40 50 50 50 50 0.31250 思路: 递归枚举对的题目个数,最后TLE之过40%: 知道正确解法是DP, ...
- Windows Install Twisted 安装Twisted
1.下载twisted exe https://twistedmatrix.com/Releases/Twisted/15.4/ (注意最新版16.x没有适用于windows的exe,只能用旧版) 2 ...
- web开发----jsp中通用模版的引用 include的用法
1.静态引入的示例 通过对两种用法的了解之后 我们现在 使用静态引入 因为上述原因 我的模版页中 只有div 不会有 path等定义 也不会有html标签 如下: 我的header.jsp 全 ...