C. Circular RMQ

题目大意:

好激动,带懒标记的上百行的线段树带A掉这道题,线段树真好玩,可以看出来是裸的带懒标记的线段树
难点1:读入的时候怎么判断是3个数还是2个数,看快读最后有无读入空格,如果读入了space就等于1
难点2:线段是环形的l <= r正常区间,l > r 就讲区间分成 1 ~ r, l ~ n, 读入的是0~n-1我们处理成1 ~ n
难点3:线段树和懒标记,我也是初学者不会讲,找大佬学呗

Ac code

#include <bits/stdc++.h>
using namespace std;typedef long long ll;
const int N = 2e5 + 10;
ll w[N];
struct Node{ll l, r, minv, lazy;
}tr[N << 2];int space;
inline ll read()
{space = 0;ll x = 0, f = 1;char c = getchar();while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9'){x = x * 10 + c - '0';c = getchar();}space = c == ' ';return x * f;
}inline void print(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) print(x / 10);putchar(x % 10 + '0');
}inline ll ls(ll u) {return u << 1; }
inline ll rs(ll u) {return u << 1 | 1; }inline void pushup(ll u, ll l, ll r){tr[u] = {l, r, min(tr[ls(u)].minv, tr[rs(u)].minv), 0};
}inline void pushdown(ll u){if(tr[u].lazy){ //懒标记tr[ls(u)].minv += tr[u].lazy;tr[rs(u)].minv += tr[u].lazy;tr[ls(u)].lazy += tr[u].lazy;tr[rs(u)].lazy += tr[u].lazy;tr[u].lazy = 0;}
}void build(ll u, ll l, ll r)
{if(l == r){tr[u] = {l, r, w[l], 0};return;}ll mid = l + r >> 1;build(ls(u), l, mid);build(rs(u), mid + 1, r);pushup(u, l, r);
}void modify(ll u, ll l, ll r, ll x)
{if(l <= tr[u].l && tr[u].r <= r){tr[u].minv += x;tr[u].lazy += x;return;}pushdown(u);ll mid = tr[u].l + tr[u].r >> 1;if(l <= mid) modify(ls(u), l, r, x);if(mid < r)  modify(rs(u), l, r, x);pushup(u, tr[u].l, tr[u].r);
}ll query(ll u, ll l, ll r)
{if(l <= tr[u].l && tr[u].r <= r)return tr[u].minv;pushdown(u);ll mid = tr[u].l + tr[u].r >> 1, minv = __INT64_MAX__;if(l <= mid) minv = min(minv, query(ls(u), l, r));if(mid < r)  minv = min(minv, query(rs(u), l, r));return minv;
}int main()
{#ifdef LOCALfreopen("in.txt", "r", stdin);#endifll n = read();for(int i = 1; i <= n; ++i) w[i] = read();build(1, 1, n); //建树ll m = read();    while(m--){ll x = read(), y = read();if(space) //inc{ll v = read();++x, ++y;if(x <= y)modify(1, x, y, v);else modify(1, 1, y, v), modify(1, x, n, v);}else    //rmq{++x, ++y;if(x <= y){print(query(1, x, y));putchar('\n');}else{print(min(query(1, 1, y), query(1, x, n)));putchar('\n');}}}return 0;
}

今天是被大运河虐惨的一天… ---------------------------------------------------------------------------------------------2021.12.18

Codeforces 52C相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

最新文章

  1. java commons.util_Java — CommonUtil
  2. Redis大乱探------哨兵(二)
  3. 李嘉诚今日正式退休,来看看他一生都做过哪些牛逼的事
  4. 19.C++-(=)赋值操作符、初步编写智能指针
  5. thread local性能 c++_MySQL 5.7 amp; MySQL 8.0 性能对比
  6. jquery与Ajax() 调用后台方法
  7. json转换成dart类 JSON to Dart
  8. 利用rowid删除数据,提升性能
  9. anaconda flaks 安装_Anaconda 安装和配置
  10. 计算机一进制一加一等于一,1加1等于几所有答案_灯谜一加一打一字的答案
  11. 论文解读:Prediction of Protein–Protein Interaction Sites Using Convolutional Neural Network
  12. Spring Boot开发登录、退出功能
  13. 语义计算_语义多态性如何在量子计算中起作用
  14. wxPython 2 - wxPython基础
  15. Intellij-出现Module ** must not contain source root **. The root already belongs to module **
  16. ADDS, DHCP建立
  17. 一次触摸屏中断调试引发的深入探究
  18. html特效站长之家,jQuery特效
  19. 1分钟链圈 | 全球加密货币市值反弹598.38亿人民币!成都市将利用区块链等技术推动旅游产业发展...
  20. 永中word页码怎么从第二页开始_办公软件操作技巧087:如何在word中自动生成目录并同步更新目录...

热门文章

  1. python在匿名函数作和_python之路——内置函数和匿名函数
  2. js页面初始化方法只调用一次_跟我学 “Linux” 小程序 Web 版开发(三):云开发相关数据调用
  3. 基于Ogre的DeferredShading(延迟渲染)的实现以及应用
  4. 信号生成及DFT的python实现
  5. vivo6.0系统怎么样不用root激活XPOSED框架的方法
  6. 题解 P3978 【[TJOI2015]概率论】
  7. larvel nginx 配置
  8. 小鱼易连全系新品正式发布 引爆音视频会议行业核聚变
  9. ise和modelsim联合仿真的一些准备
  10. linux6.5+5.4 vncserver配置