Submission #95002

# Submission time Handle Problem Language Result Execution time Memory
95002 2019-01-26T15:30:08 Z bogdan10bos Sterilizing Spray (JOI15_sterilizing) C++14
20 / 100
206 ms 11532 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

const int NMAX = 1e5;

int N, Q, K;
vector<int> init;

class SegmentTree
{
public:
    LL ans;
    vector<int> mx, mn, lzy;
    vector<LL> sum;

    void remake(int nod)
    {
        sum[nod] = sum[nod * 2] + sum[nod * 2 + 1];
        mx[nod] = max(mx[nod * 2], mx[nod * 2 + 1]);
        mn[nod] = min(mn[nod * 2], mn[nod * 2 + 1]);
    }

    void lazy(int nod, int st, int dr)
    {
        if(lzy[nod] == -1)  return;

        int mij = st + (dr - st) / 2;

        int val = lzy[nod];
        lzy[nod * 2] = lzy[nod * 2 + 1] = val;

        sum[nod * 2] = 1LL * (mij - st + 1) * val;
        mx[nod * 2] = mn[nod * 2] = val;

        sum[nod * 2 + 1] = 1LL * (dr - mij) * val;
        mx[nod * 2] = mn[nod * 2] = val;

        lzy[nod] = -1;
    }

    void B(int nod, int st, int dr)
    {
        lzy[nod] = -1;

        if(st == dr)
        {
            sum[nod] = mn[nod] = mx[nod] = init[st];
            return;
        }

        int mij = st + (dr - st) / 2;
        B(nod * 2, st, mij);
        B(nod * 2 + 1, mij + 1, dr);

        remake(nod);
    }

    void U(int nod, int st, int dr, int pos, int val)
    {
        if(st == dr)
        {
            sum[nod] = mx[nod] = mn[nod] = val;
            return;
        }

        lazy(nod, st, dr);

        int mij = st + (dr - st) / 2;
        if(pos <= mij)  U(nod * 2, st, mij, pos, val);
        else    U(nod * 2 + 1, mij + 1, dr, pos, val);

        remake(nod);
    }

    void U(int nod, int st, int dr, int sti, int dri, int val)
    {
        if(sti <= st && dr <= dri)
        {
            if(mn[nod] / val == mx[nod] / val)
            {
                mn[nod] = mx[nod] = mn[nod] / val;
                sum[nod] = 1LL * (dr - st + 1) * mn[nod];
                lzy[nod] = mn[nod];
                return;
            }

            int mij = st + (dr - st) / 2;
            U(nod * 2, st, mij, sti, dri, val);
            U(nod * 2 + 1, mij + 1, dr, sti, dri, val);
            remake(nod);
            return;
        }

        lazy(nod, st, dr);
        int mij = st + (dr - st) / 2;

        if(sti <= mij)  U(nod * 2, st, mij, sti, dri, val);
        if(mij < dri)   U(nod * 2 + 1, mij + 1, dr, sti, dri, val);

        remake(nod);
    }

    void Q(int nod, int st, int dr, int sti, int dri)
    {
        if(sti <= st && dr <= dri)
        {
            ans += sum[nod];
            return;
        }

        lazy(nod, st, dr);

        int mij = st + (dr - st) / 2;
        if(sti <= mij)  Q(nod * 2, st, mij, sti, dri);
        if(mij < dri)   Q(nod * 2 + 1, mij + 1, dr, sti, dri);
    }

    void build()
    {
        sum.resize(4 * N + 2);
        mx.resize(4 * N + 2);
        mn.resize(4 * N + 2);
        lzy.resize(4 * N + 2);
        B(1, 1, N);
    }

    void update(int pos, int val)
    {
        U(1, 1, N, pos, val);
    }

    void divide(int st, int dr, int K)
    {
        if(K == 1)  return;
        U(1, 1, N, st, dr, K);
    }

    LL query(int st, int dr)
    {
        ans = 0;
        Q(1, 1, N, st, dr);
        return ans;
    }
}aint;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &Q, &K);
    init.resize(N + 2);
    for(int i = 1; i <= N; i++) scanf("%d", &init[i]);
    aint.build();
    for(int q = 1; q <= Q; q++)
    {
        int op;
        scanf("%d", &op);
        if(op == 1)
        {
            int pos, val;
            scanf("%d%d", &pos, &val);
            aint.update(pos, val);
        }
        else if(op == 2)
        {
            int st, dr;
            scanf("%d%d", &st, &dr);
            aint.divide(st, dr, K);
        }
        else if(op == 3)
        {
            int st, dr;
            scanf("%d%d", &st, &dr);
            LL ans = aint.query(st, dr);
            printf("%lld\n", ans);
        }
    }

    return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:158:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &Q, &K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:160:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= N; i++) scanf("%d", &init[i]);
                                 ~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:165:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &op);
         ~~~~~^~~~~~~~~~~
sterilizing.cpp:169:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &pos, &val);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:175:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &st, &dr);
             ~~~~~^~~~~~~~~~~~~~~~~~
sterilizing.cpp:181:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &st, &dr);
             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 3 ms 504 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 6648 KB Output is correct
2 Correct 61 ms 5084 KB Output is correct
3 Correct 62 ms 8708 KB Output is correct
4 Correct 74 ms 10972 KB Output is correct
5 Correct 86 ms 11532 KB Output is correct
6 Correct 95 ms 11484 KB Output is correct
7 Correct 86 ms 11512 KB Output is correct
8 Correct 90 ms 11512 KB Output is correct
9 Correct 91 ms 11384 KB Output is correct
10 Correct 85 ms 11384 KB Output is correct
11 Correct 85 ms 11388 KB Output is correct
12 Correct 91 ms 11384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1272 KB Output is correct
2 Correct 24 ms 4344 KB Output is correct
3 Correct 32 ms 4472 KB Output is correct
4 Correct 89 ms 3684 KB Output is correct
5 Correct 143 ms 9992 KB Output is correct
6 Correct 206 ms 10076 KB Output is correct
7 Correct 75 ms 10104 KB Output is correct
8 Correct 133 ms 10156 KB Output is correct
9 Correct 116 ms 9848 KB Output is correct
10 Correct 117 ms 9952 KB Output is correct
11 Correct 113 ms 9820 KB Output is correct
12 Correct 125 ms 9904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 6264 KB Output isn't correct
2 Halted 0 ms 0 KB -