Submission #1303775

#TimeUsernameProblemLanguageResultExecution timeMemory
1303775the_commando_xSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
120 ms8660 KiB
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

using pii = pair<int, int>;
using vii = vector<pii>;
using vvii = vector<vii>;

using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

using pll = pair<l, l>;
using vll = vector<pll>;
using vvll = vector<vll>;

using d = double;
using vd = vector<d>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;

using vb = vector<bool>;
using vvb = vector<vb>;
using pbb = pair<bool, bool>;
using vbb = vector<pbb>;

#define ff first
#define ss second

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty())
    {
        (void)freopen((name + ".in").c_str(), "r", stdin);
        (void)freopen((name + ".out").c_str(), "w", stdout);
    }
}

const ld pi = 3.14159265358979323846;

const l LINF = 1e18;
const l INF = 1e9;

const l MOD = 1e9 + 7;
// const l MOD = 998244353;

const l MAXN = 2e5 + 5;

struct Node
{
    l sum, mx;
};

struct SegTree
{
    int n;
    vector<Node> t;
    vl a;

    SegTree(int n) : n(n)
    {
        t.assign(4 * n + 5, {0, 0});
        a.assign(n + 1, 0);
    }

    SegTree(const vl &v) : n((int)v.size() - 1)
    {
        a = v;
        t.assign(4 * n + 5, {0, 0});

        build(1, 1, n);
    }

    void recalculate(int node)
    {
        t[node].sum = t[2 * node].sum + t[2 * node + 1].sum;
        t[node].mx = max(t[2 * node].mx, t[2 * node + 1].mx);
    }

    void build(int node, int left, int right)
    {
        if (left == right)
            t[node].sum = t[node].mx = a[left];
        else
        {
            int mid = (left + right) / 2;

            build(2 * node, left, mid);
            build(2 * node + 1, mid + 1, right);

            recalculate(node);
        }
    }

    void update(int i, l val)
    {
        update(1, 1, n, i, val);
    }

    void update(int node, int left, int right, int i, l val)
    {
        if (left == right)
            t[node].sum = t[node].mx = val;
        else
        {
            int mid = (left + right) / 2;

            if (i <= mid)
                update(2 * node, left, mid, i, val);
            else
                update(2 * node + 1, mid + 1, right, i, val);

            recalculate(node);
        }
    }

    void spray(int x, int y, l K)
    {
        spray(1, 1, n, x, y, K);
    }

    void spray(int node, int left, int right, int x, int y, l K)
    {
        if (t[node].mx == 0 || y < left || right < x)
            return;
        else if (left == right)
            t[node].sum /= K, t[node].mx /= K;
        else
        {
            int mid = (left + right) / 2;

            spray(2 * node, left, mid, x, y, K);
            spray(2 * node + 1, mid + 1, right, x, y, K);

            recalculate(node);
        }
    }

    l query(int a, int b)
    {
        return query(1, 1, n, a, b);
    }

    l query(int node, int left, int right, int x, int y)
    {
        if (y < left || right < x)
            return 0;
        else if (x <= left && right <= y)
            return t[node].sum;
        else
        {
            int mid = (left + right) / 2;

            return query(2 * node, left, mid, x, y) + query(2 * node + 1, mid + 1, right, x, y);
        }
    }
};

void solve()
{
    l N, Q, K;
    cin >> N >> Q >> K;

    vl a(N + 1);
    for (int i = 1; i <= N; ++i)
        cin >> a[i];

    SegTree seg(a);

    while (Q--)
    {
        l S, T, U;
        cin >> S >> T >> U;

        if (S == 1)
            seg.update(T, U);
        else if (S == 2 && K != 1)
            seg.spray(T, U, K);
        else if (S == 3)
            cout << seg.query(T, U) << '\n';
    }
}

int main()
{
    setIO("");

#ifndef ONLINE_JUDGE
    // setIO("filename");
#endif

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

    return 0;
}

Compilation message (stderr)

sterilizing.cpp: In function 'void setIO(std::string)':
sterilizing.cpp:53:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:54:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...