Description

Input

Output

Sample Input

4
3
2
4
3
3
1 1 3 2
3 3 4 2
1 3 3 4

Sample Output

3
2
5

Data Constraint


感觉这题和在纪中时候打的一场CF的A题特别像。。。

其实就是维护区间最小值。然后画画图就行了。


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define reg register
inline char gc() {static const int BS = 1 << 22;static unsigned char buf[BS], *st, *ed;if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);return st == ed ? EOF : *st++;
}
#define gc getchar
inline int read() {int res = 0;char ch=gc();bool fu=0;while(!isdigit(ch))fu|=(ch=='-'),ch=gc();while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=gc();return fu?-res:res;
}int n, L[100005];
int st[100005*20][21];inline int query(int l, int r)
{int k = log(r - l + 1) / log(2);return min(st[l][k], st[r - (1 << k) + 1][k]);
}int main()
{
//    freopen("cusor.in", "r", stdin);
//    freopen("cusor.out", "w", stdout);n = read();for (reg int i = 1 ; i <= n ; i ++) L[i] = read();for (reg int i = 1 ; i <= n ; i ++) st[i][0] = L[i];for (reg int j = 1 ; j <= 20 ; j ++)for (reg int i = 1 ; i <= n - (1 << j) + 1 ; i ++)st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);int q = read();while(q--){int x1 = read(), y1 = read(), x2 = read(), y2 = read();if (x1 > x2) swap(x1, x2), swap(y1, y2);int mn = query(x1, x2);int ans = abs(x2 - x1);if (mn <= y1 and mn <= y2) ans += abs(y1 - mn) + abs(y2 - mn);else ans += abs(y1 - y2);printf("%d\n", ans);}return 0;
}

转载于:https://www.cnblogs.com/BriMon/p/9735651.html

[JZOJ5863] 【NOIP2018模拟9.11】移动光标相关推荐

  1. 备战Noip2018模拟赛11(B组)T4 Path 好路线

    10月27日备战Noip2018模拟赛11(B组) T4路径好路线 题目描述 nodgd在旅游.现在,nodgd要从城市的西北角走到东南角去.这个城市的道路并不平坦,nodgd希望找出一条相对比较好走 ...

  2. NOIP2018 模拟 9.11

    ISIJ 2018 很多序列(Training Round D4T3) 题目名称:很多序列 文件名:sequences.in / sequences.out 题目描述 假设 $ x_1 < x_ ...

  3. jozj5945. 【NOIP2018模拟11.02】昆特牌

    5945. [NOIP2018模拟11.02]昆特牌 Description 作为一个资深OIer,你被邀请到位于波兰的CDPR总部参观.但没想到你刚一到就遇到了麻烦.昆特牌的数据库发生了故障.原本昆 ...

  4. C语言模拟11答案,C语言模拟试题11答案.doc

    C语言模拟试题11答案.doc 下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览.不比对内容而直接下载带来的问题本站不予受理. 2.下载的文档,不会出现我们的网址水印. 3.该文档 ...

  5. EZ 2018 06 17 NOIP2018 模拟赛(十九)

    这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...

  6. 备战Noip2018模拟赛3(B组)T1 Apple 韬韬抢苹果

    10月3日备战Noip2018模拟赛3(B组) T1 Apple韬韬抢苹果 题目描述 又到了收获的季节,树上结了许多韬韬,错了,是许多苹果,有很多个小韬韬都来摘苹果.每个韬韬都想要最大的苹果,所以发生 ...

  7. 备战Noip2018模拟赛3(B组) T2 Dance 开场舞蹈

    10月3日备战Noip2018模拟赛3(B组) T2 Dance 开场舞蹈 题目描述 在全世界人民的期盼下,2008年北京奥林匹克运动会终于隆重召开了! 为了展示中华民族博大精深的优秀传统文化,负责开 ...

  8. 备战Noip2018模拟赛5(B组)T2 Tree 采果子

    10月4日备战Noip2018模拟赛5(B组) T2 Tree采果子 题目描述 LYL大牛今天心情不错,于是走到埃及郊外旅游.他边走边向四周望望,发现周围有许多果树.这些树之间互相到达的时间LYL是知 ...

  9. jzoj 5906. 【NOIP2018模拟10.15】传送门(树形dp)

    5906. [NOIP2018模拟10.15]传送门 Description 8102年,Normalgod在GLaDOS的帮助下,研制出了传送枪.但GLaDOS想把传送枪据为己有,于是把Normal ...

最新文章

  1. 『高级篇』docker容器来说什么是微服务(三)
  2. Zabbix poller processes more than 75% busy
  3. java实验七输入输出流_实验六_Java的输入输出流
  4. 【收藏】Linux系统常用命令速查手册(附PDF下载链接)
  5. 主流开源开发者工具落地阿里云,进一步提升开发者体验
  6. hadoop-02-关闭防火墙
  7. Java必备技能:IDEA一定要懂的32条快捷键
  8. php操作elasticsearch
  9. 基于springboot的民办职业学校缴费系统
  10. 系统集成项目管理工程师(中级)考试心得经验
  11. Ionic系列——Ionic介绍
  12. html文本特效代码逐个出现,JS特效文字逐个显示
  13. 苹果开发者账号申请流程完整版
  14. c# NPOI 导出Excel 冻结窗格
  15. 写一篇讲解优芽动画知识的教案
  16. 2022全国职业技能大赛-网络系统管理-Debian模块:CA证书服务
  17. 数据结构概述3 对称矩阵、树和二叉树
  18. 【图像去噪】基于小波变换(中值、硬阙值、软阙值)的图像去噪含Matlab源码
  19. excel和python建模_如何用Python提高办公(Excel)效率?
  20. MATLAB scatter 画二维/三维散点图时 用颜色表示数值大小 colorbar

热门文章

  1. 每天一道LeetCode-----回文链表
  2. 计算机网络基础昆明理工大学,昆明理工大学 计算机网络基础 实验四
  3. Java堆排序递归_大顶堆第二弹----堆排序(递归实现)
  4. POJ 1742 Coins
  5. linux usb视频开发板,ARM开发板上USB 摄像头图像采集实现
  6. LeTax如何多行注释
  7. AttributeError系列之:AttributeError: 'tuple' object has no attribute 'shape'
  8. vector中的圆括号和花括号
  9. 8086汇编-实验5(微调)-用栈实现数据交换位置
  10. 实际电压/流源模型及其等效分析