Submission #957662

# Submission time Handle Problem Language Result Execution time Memory
957662 2024-04-04T07:25:40 Z vjudge1 Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
2513 ms 11344 KB
#include <bits/stdc++.h>
#define Y8o "Sterilizing Spray"
#define maxn 100005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)

using namespace std;

/// okay?
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof()   /// ------------------inp_out file!-----------------///
{
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void ctime()   /// ------------------check time!-----------------///
{
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/// okay!

int n, Q, k;
int a[maxn];
struct dl
{
    int id, f, s;
} qr[maxn];
pii st[4 * maxn]; /// max + pos
ll st2[4 * maxn]; /// sum

void build(int id = 1, int l = 1, int r = n)
{
    if(l == r)
    {
        st[id] = {a[l], l};
        st2[id] = 1ll * a[l];
        return ;
    }

    int mid = (l + r) >> 1;

    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);

    st[id] = max(st[id * 2], st[id * 2 + 1]);
    st2[id] = st2[id * 2] + st2[id * 2 + 1];
}

void update(int i, int val, int id = 1, int l = 1, int r = n)
{
    if(i < l || r < i) return ;
    if(l == r)
    {
        st[id] = {val, l};
        st2[id] = 1ll * val;
        return ;
    }

    int mid = (l + r) >> 1;

    update(i, val, id * 2, l, mid);
    update(i, val, id * 2 + 1, mid + 1, r);

    st[id] = max(st[id * 2], st[id * 2 + 1]);
    st2[id] = st2[id * 2] + st2[id * 2 + 1];
}

pii getma(int u, int v, int id = 1, int l = 1, int r = n)
{
    if(v < l || r < u) return {0, 0};
    if(u <= l && r <= v) return st[id];

    int mid = (l + r) >> 1;

    return max( getma(u, v, id * 2, l, mid), getma(u, v, id * 2 + 1, mid + 1, r) );
}

ll getsum(int u, int v, int id = 1, int l = 1, int r = n)
{
    if(v < l || r < u) return 0;
    if(u <= l && r <= v) return st2[id];

    int mid = (l + r) >> 1;

    return getsum(u, v, id * 2, l, mid) + getsum(u, v, id * 2 + 1, mid + 1, r);
}

void sub1()
{
    build();

    for(int i = 1; i <= Q; i ++)
    {
        int id = qr[i].id, u = qr[i].f, v = qr[i].s, l = u, r = v;
        if(id == 1) update(u, v); /// a[u] = v
        else if(id == 3) cout << getsum(l, r) << '\n';
    }
}

void sub2()
{
    build();

    for(int i = 1; i <= Q; i ++)
    {
        int id = qr[i].id, u = qr[i].f, v = qr[i].s, l = u, r = v;
        if(id == 1) update(u, v); /// a[u] = v
        else if(id == 2)
        {
            vector<pii> store;

            while(1)
            {
                pii best = getma(l, r);
                if(best.first != 0)
                {
                    store.push_back(best);
                    update(best.second, 0);
                }
                else break;
            }
            for(pii x : store)
            {
                int val = x.first, pos = x.second;
                update(pos, val / k);
            }
        }
        else cout << getsum(l, r) << '\n';
    }
}

void solve()
{
    cin >> n >> Q >> k;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= Q; i ++) cin >> qr[i].id >> qr[i].f >> qr[i].s;

    if(k == 1) sub1();
    else sub2();
}


int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --)
    {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

sterilizing.cpp: In function 'void iof()':
sterilizing.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(Y8o".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 8 ms 4444 KB Output is correct
4 Correct 25 ms 4636 KB Output is correct
5 Correct 26 ms 4700 KB Output is correct
6 Correct 17 ms 4684 KB Output is correct
7 Correct 22 ms 4696 KB Output is correct
8 Correct 23 ms 4696 KB Output is correct
9 Correct 32 ms 4700 KB Output is correct
10 Correct 22 ms 4952 KB Output is correct
11 Correct 21 ms 4700 KB Output is correct
12 Correct 23 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 8452 KB Output is correct
2 Correct 34 ms 9948 KB Output is correct
3 Correct 30 ms 9684 KB Output is correct
4 Correct 37 ms 10508 KB Output is correct
5 Correct 56 ms 11092 KB Output is correct
6 Correct 46 ms 11008 KB Output is correct
7 Correct 58 ms 11344 KB Output is correct
8 Correct 45 ms 10964 KB Output is correct
9 Correct 42 ms 10968 KB Output is correct
10 Correct 51 ms 11084 KB Output is correct
11 Correct 52 ms 10836 KB Output is correct
12 Correct 45 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5212 KB Output is correct
2 Correct 21 ms 7144 KB Output is correct
3 Correct 27 ms 7336 KB Output is correct
4 Correct 70 ms 8028 KB Output is correct
5 Correct 83 ms 8416 KB Output is correct
6 Correct 82 ms 8448 KB Output is correct
7 Correct 49 ms 8604 KB Output is correct
8 Correct 84 ms 10024 KB Output is correct
9 Correct 78 ms 10208 KB Output is correct
10 Correct 78 ms 10032 KB Output is correct
11 Correct 78 ms 10104 KB Output is correct
12 Correct 79 ms 10116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 8368 KB Output is correct
2 Correct 447 ms 8464 KB Output is correct
3 Correct 1048 ms 8252 KB Output is correct
4 Correct 548 ms 8392 KB Output is correct
5 Correct 812 ms 9288 KB Output is correct
6 Correct 1063 ms 9236 KB Output is correct
7 Correct 758 ms 9668 KB Output is correct
8 Correct 1573 ms 9992 KB Output is correct
9 Correct 1296 ms 10252 KB Output is correct
10 Correct 1642 ms 10524 KB Output is correct
11 Correct 969 ms 10060 KB Output is correct
12 Correct 2513 ms 10064 KB Output is correct