Submission #695401

# Submission time Handle Problem Language Result Execution time Memory
695401 2023-02-05T05:04:48 Z tamthegod Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
350 ms 8140 KB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, q, k;
int a[maxN];
struct TNode
{
    int sum, _max;
    TNode operator + (const TNode& other) const
    {
        TNode tmp;
        tmp.sum = sum + other.sum;
        tmp._max = max(_max, other._max);
        return tmp;
    }
} st[4 * maxN];
void build(int id, int l, int r)
{
    if(l == r)
    {
        st[id] = {a[l], a[l]};
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
void update(int id, int l, int r, int u, int v)
{
    if(l > v || r < u || !st[id]._max) return;
    if(l == r)
    {
        st[id].sum /= k;
        st[id]._max /= k;
        return;
    }
    int mid = (l + r) / 2;
    update(id * 2, l, mid, u, v);
    update(id * 2 + 1, mid + 1, r, u, v);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
void update1(int id, int l, int r, int pos, int val)
{
    if(l == r)
    {
        st[id] = {val, val};
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid) update1(id * 2, l, mid, pos, val);
    else update1(id * 2 + 1, mid + 1, r, pos, val);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
int get(int id, int l, int r, int u, int v)
{
    if(l > v || r < u) return 0;
    if(l >= u && r <= v) return st[id].sum;
    int mid = (l + r) / 2;
    return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v);
}
void ReadInput()
{
    cin >> n >> q >> k;
    for(int i=1; i<=n; i++)
        cin >> a[i];
}
void Solve()
{
    build(1, 1, n);
    while(q--)
    {
        int type;
        cin >> type;
        if(type == 1)
        {
            int a, b;
            cin >> a >> b;
            update1(1, 1, n, a, b);
        }
        else if(type == 2)
        {
            int l, r;
            cin >> l >> r;
            if(k > 1) update(1, 1, n, l, r);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << get(1, 1, n, l, r) << '\n';
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 6 ms 404 KB Output is correct
5 Correct 6 ms 472 KB Output is correct
6 Correct 5 ms 668 KB Output is correct
7 Correct 6 ms 548 KB Output is correct
8 Correct 6 ms 564 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 6 ms 472 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 14 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 5096 KB Output is correct
2 Correct 57 ms 4664 KB Output is correct
3 Correct 56 ms 6996 KB Output is correct
4 Correct 82 ms 7676 KB Output is correct
5 Correct 85 ms 8140 KB Output is correct
6 Correct 74 ms 8124 KB Output is correct
7 Correct 62 ms 8028 KB Output is correct
8 Correct 86 ms 8092 KB Output is correct
9 Correct 70 ms 7920 KB Output is correct
10 Correct 60 ms 7996 KB Output is correct
11 Correct 123 ms 7992 KB Output is correct
12 Correct 88 ms 7960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1116 KB Output is correct
2 Correct 21 ms 2968 KB Output is correct
3 Correct 30 ms 3040 KB Output is correct
4 Correct 55 ms 2724 KB Output is correct
5 Correct 76 ms 6732 KB Output is correct
6 Correct 70 ms 6616 KB Output is correct
7 Correct 74 ms 6796 KB Output is correct
8 Correct 77 ms 6724 KB Output is correct
9 Correct 66 ms 6516 KB Output is correct
10 Correct 104 ms 6512 KB Output is correct
11 Correct 66 ms 6544 KB Output is correct
12 Correct 76 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 4484 KB Output is correct
2 Correct 132 ms 4680 KB Output is correct
3 Correct 123 ms 4032 KB Output is correct
4 Correct 144 ms 3552 KB Output is correct
5 Correct 183 ms 7848 KB Output is correct
6 Correct 196 ms 7936 KB Output is correct
7 Correct 181 ms 7904 KB Output is correct
8 Correct 195 ms 7960 KB Output is correct
9 Correct 192 ms 7788 KB Output is correct
10 Correct 216 ms 7756 KB Output is correct
11 Correct 180 ms 7748 KB Output is correct
12 Correct 350 ms 7768 KB Output is correct