Submission details
Task:Dynamic Range Minimum Queries
Sender:aalto26dh_009
Submission time:2026-09-21 18:44:08 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.23 sdetails

Code

#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include "bits/stdc++.h"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i, a, b) for(__typeof(b) i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for(__typeof(a) i = a, _b = b; i >= _b; --i)
#define ALL(a) (a).begin(), (a).end()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define dq deque<int>
#define nend '\n'
using namespace std;

const ll inf = 1e18;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int MOD = 1e9 + 7;
const ll hashi = 2e9 + 11;

inline ll add(ll a, ll b) { return (a + b) % MOD; }
inline ll sub(ll a, ll b) { return ((a - b) % MOD + MOD) % MOD; }
inline ll mul(ll a, ll b) { return (a * b) % MOD; }

inline ll binpow(ll a, ll b) {
    ll res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

inline ll modInverse(ll n) {
    return binpow(n, MOD - 2);
}

inline ll modDivide(ll a, ll b) {
    return (a % MOD * modInverse(b)) % MOD;
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1; y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extended_gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

void init_code() {
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/// LAZY: RANGE ADD + RANGE MIN
/// update(u,v,val): a[u..v] += val
/// get(u,v)       : min(a[u..v])
/// Input a[i]     : update(i,i,a[i])
/// Example: a = {5,1,4,2}, update(1,2,3) -> {8,4,4,2}, get(1,3) = 4
const int N=2e5+2;
const int SIZE=N*4+5;
int n,q;
ll st[SIZE],lazy[SIZE];
void push(int id) {
    if (lazy[id]!=0) {
        ll a=lazy[id];
        lazy[id*2]+=a;
        lazy[id*2+1]+=a;
        st[id*2]+=a;
        st[id*2+1]+=a;
        lazy[id]=0;
    }
}
void update(int u, int v, ll val, int id=1, int l=1, int r=n) {
    if (r<u||l>v) return;
    if (l>=u&&r<=v) {
        st[id]+=val;
        lazy[id]+=val;
        return;
    }
    push(id);
    int mid=(l+r)>>1;
    update(u,v,val,id*2,l,mid);
    update(u,v,val,id*2+1,mid+1,r);
    st[id]=min(st[id*2],st[id*2+1]);
}
ll get(int u, int v, int id=1, int l=1, int r=n) {
    if (r<u||l>v) return inf;
    if (l>=u&&r<=v) return st[id];
    push(id);
    int mid=(l+r)>>1;
    return min(get(u,v,id*2,l,mid),get(u,v,id*2+1,mid+1,r));
}
/// BONUS: first index i in [u,v] with a[i] <= k, -1 if none. O(log n)
int firstLE(int u, int v, ll k, int id=1, int l=1, int r=n) {
    if (r<u||l>v||st[id]>k) return -1;
    if (l==r) return l;
    push(id);
    int mid=(l+r)>>1;
    int res=firstLE(u,v,k,id*2,l,mid);
    if (res==-1) res=firstLE(u,v,k,id*2+1,mid+1,r);
    return res;
}
/// input: n q, a[1..n], then q lines:
/// 1 l r x : a[l..r] += x
/// 2 l r   : print min a[l..r]
void solve() {
    cin >> n >> q;
    FOR(i,1,n) {
        ll x;
        cin >> x;
        update(i,i,x);
    }
    while (q--) {
        int c;
        cin >> c;
        if (c==1) {
            ll k,u;
            cin >> k >> u;
            update(k,k,u);
        }else {
            ll a,b;
            cin >> a >> b;
            cout << get(a,b) << nend;
        }
    }
}
int main() {
    init_code();

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

}

Test details

Test 1

Verdict:

input
8 80
7 6 4 6 2 9 4 8
2 1 1
2 1 2
2 1 3
...

correct output
7
6
4
4
2
...

user output
7
6
4
4
2
...

Feedback: Incorrect character on line 37 col 2: expected "10", got "17"

Test 2

Verdict:

input
200000 200000
398739055 65343131 699208332 3...

correct output
28609
129890
20378
20378
311522
...

user output
28609
129890
20378
20378
311522
...

Feedback: Incorrect character on line 1454 col 1: expected "88017", got "173250"