ICPC Aisa Yinchuan, 线段树(max,add)G.Pot!!

Posted thjkhdf12

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ICPC Aisa Yinchuan, 线段树(max,add)G.Pot!!相关的知识,希望对你有一定的参考价值。

技术图片
  1 #include<iostream>
  2 #include<string>
  3 #include<queue>
  4 #include<stack>
  5 #include<vector>
  6 #include<map>
  7 #include<cstdio>
  8 #include<cstdlib>
  9 #include<algorithm>
 10 #include<set>
 11 #include<list>
 12 #include<iomanip>
 13 #include<cstring>
 14 #include<cmath>
 15 #include<limits>
 16 using namespace std;
 17 
 18 #define au auto
 19 #define debug(i) cout<<"<debug> "<<i<<"<debug>"<<endl
 20 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
 21 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
 22 #define LLL __int128
 23 #define Re register
 24 #define il inline
 25 #define mem(a,b) memset(a,(b),sizeof(a))
 26 typedef pair<int, int> intpair;
 27 typedef long long int LL;
 28 const int INF = 0x3f3f3f3f;
 29 const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
 30 
 31 const int maxn = 5000010;
 32 int a[maxn];
 33 int n, q;
 34 #define lc(x) x<<1
 35 #define rc(x) x<<1|1
 36 il int min(int a, int b)
 37 {
 38     return a > b ? b : a;
 39 }
 40 struct tree
 41 {
 42     int a;
 43     int l, r;
 44     int tag;
 45     tree()
 46     {
 47         tag = 0;
 48         l = 0;
 49         r = 0;
 50         a = 0;
 51     }
 52 }node1[maxn], node2[maxn], node3[maxn], node4[maxn];
 53 
 54 void build(int x, int l, int r, tree * node)
 55 {
 56     node[x].l = l;
 57     node[x].r = r;
 58     if (l == r)
 59     {
 60         node[x].a = a[l];
 61         return;
 62     }
 63     int mid = (l + r) >> 1;
 64     build(lc(x), l, mid, node);
 65     build(rc(x), mid + 1, r, node);
 66     node[x].a = max(node[lc(x)].a, node[rc(x)].a);
 67 }
 68 inline void push_down(int x, tree* node)
 69 {
 70     node[lc(x)].tag += node[x].tag;
 71     node[lc(x)].a += node[x].tag;
 72     node[rc(x)].a += node[x].tag;
 73     node[rc(x)].tag += node[x].tag;
 74     node[x].tag = 0;
 75 }
 76 inline void update(int left, int right, int x, int k, tree* node)
 77 {
 78     if (left <= node[x].l && node[x].r <= right)
 79     {
 80         node[x].a += k;
 81         node[x].tag += k;
 82         return;
 83     }
 84     push_down(x, node);
 85     int mid = (node[x].l + node[x].r) >> 1;
 86     if (left <= mid) update(left, right, lc(x), k, node);
 87     if (right > mid) update(left, right, rc(x), k, node);
 88     node[x].a = max(node[lc(x)].a, node[rc(x)].a);
 89 }
 90 int query(int left, int right, int x, tree* node)
 91 {
 92     int res = -INF;
 93     if (left <= node[x].l && node[x].r <= right) return node[x].a;
 94     int mid = (node[x].l + node[x].r) >> 1;
 95     if (left <= mid) res = max(res, query(left, right, lc(x), node));
 96     if (right > mid) res = max(res, query(left, right, rc(x), node));
 97     return res;
 98 }
 99 
100 int main()
101 {
102     cin >> n >> q;
103     build(1, 1, n, node1);
104     build(1, 1, n, node2);
105     build(1, 1, n, node3);
106     build(1, 1, n, node4);
107     mfor(i, 1, q)
108     {
109         string s;
110         Re int a, b, c;
111         cin >> s >> a >> b;
112         if (s == "MAX")
113         {
114             int maxn1 = -INF;
115             int maxn2 = -INF;
116             maxn1 = max(query(a, b, 1, node1), query(a, b, 1, node2));
117             maxn2 = max(query(a, b, 1, node3), query(a, b, 1, node4));
118             cout << "ANSWER " << max(maxn1, maxn2);
119         }
120         else
121         {
122             cin >> c;
123             if (c == 2) update(a, b, 1, 1, node1);
124             if (c == 3) update(a, b, 1, 1, node2);
125             if (c == 4) update(a, b, 1, 2, node1);
126             if (c == 5) update(a, b, 1, 1, node3);
127             if (c == 6) update(a, b, 1, 1, node1), update(a, b, 1, 1, node2);
128             if (c == 7) update(a, b, 1, 1, node4);
129             if (c == 8) update(a, b, 1, 3, node1);
130             if (c == 9) update(a, b, 1, 2, node2);
131             if (c == 10) update(a, b, 1, 1, node1), update(a, b, 1, 1, node3);
132         }
133     }
134 }
View Code

 

以上是关于ICPC Aisa Yinchuan, 线段树(max,add)G.Pot!!的主要内容,如果未能解决你的问题,请参考以下文章

2019 ICPC Asia Yinchuan Regional

2020ICPC 昆明 M.Stone Games(思维+可持久化线段树)

线段树 (ICPC小米预赛第一场 EPhone Network )

The Preliminary Contest for ICPC Asia Yinchuan 2019

2019 ICPC YinChuan Regional Online Contest

ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)