[JZOJ5863] 【NOIP2018模拟9.11】移动光标
生活随笔
收集整理的這篇文章主要介紹了
[JZOJ5863] 【NOIP2018模拟9.11】移动光标
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
Input
Output
Sample Input
4 3 2 4 3 3 1 1 3 2 3 3 4 2 1 3 3 4Sample Output
3 2 5Data 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】移动光标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [JSOI2008]Blue Mary的
- 下一篇: Wannafly挑战赛18C 异或和