Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I can't tell you what it really is,
- // I can only tell you what it feels like.
- #include "bits/stdc++.h"
- using namespace std;
- #define all(v) v.begin(), v.end()
- #define pb push_back
- #define P pair < int, int >
- #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
- #define reno(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
- void err(istream_iterator<string> it) {}
- template<typename T, typename... Args>
- void err(istream_iterator<string> it, T a, Args... args) {
- cout << *it << " = " << a << ' ';
- err(++it, args...);
- }
- const int N = 1e6 + 5;
- int sum[N], arr[N], lazy[N<<2], tree[N<<2];
- void build(int l, int r, int x) {
- if(l == r)
- tree[x] = sum[l];
- else {
- int mid = l + r >> 1, lc = x + x, rc = lc + 1;
- build(l, mid, lc); build(mid + 1, r, rc);
- tree[x] = min(tree[lc], tree[rc]);
- }
- }
- void prop(int l, int r, int x) {
- if(lazy[x]) {
- tree[x] += lazy[x];
- if(l ^ r) {
- int lc = x + x, rc = lc + 1;
- lazy[lc] += lazy[x];
- lazy[rc] += lazy[x];
- }
- lazy[x] = 0;
- }
- }
- void update(int l, int r, int ql, int qr, int val, int x) {
- prop(l, r, x);
- if(qr < l || r < ql)
- return;
- if(ql <= l && r <= qr) {
- lazy[x] = val;
- //reno(l, r, x, val);cout << '\n';
- prop(l, r, x);
- return;
- }
- int mid = l + r >> 1, lc = x + x, rc = lc + 1;
- update(l, mid, ql, qr, val, lc);
- update(mid + 1, r, ql, qr, val, rc);
- tree[x] = min(tree[lc], tree[rc]);
- }
- int query(int l, int r, int ql, int qr, int x) {
- if(qr < l || r < ql)
- return 2e9;
- prop(l, r, x);
- if(ql <= l and r <= qr) {
- prop(l, r, x);
- return tree[x];
- }
- int mid = l + r >> 1, lc = x + x, rc = lc + 1;
- return min(query(l, mid, ql, qr, lc), query(mid + 1, r, ql, qr, rc));
- }
- signed main(){
- fast;
- int n, let, ans(0); string s;
- cin >> n;
- build(1, n, 1);
- cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment