답안 #587986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587986 2022-07-02T15:40:41 Z MadokaMagicaFan 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 6816 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second
/* #define ONPC */

using vi = vector<int>;

/* struct lenes_aint { */
/*     int n; */
/*     vi c; */
/*     vector<ll> t, len; */
/*  */
/*     lenes_aint(vi &_c) { */
/*         c = _c; */
/*         n = sz(c); */
/*         len.assign(4*n, 0); */
/*         t.assign(4*n, 0); */
/*     } */
/*  */
/*     void */
/*     impinge(int i, int l, int r, int tl, int tr, int v) */
/*     { */
/*         int mid = (l+r)>>1; */
/*         if (l > tr || r < tl) return; */
/*         if (l >= tl && r <= tr) { */
/*             len[i] += v; */
/*             len[i] = max(len[i],0ll); */
/*             return; */
/*         } */
/*  */
/*         if (l == r) return; */
/*         impinge(i<<1,l,mid,tl,tr,v); */
/*         impinge(i<<1|1,mid+1,r,tl,tr,v); */
/*         return; */
/*     } */
/*  */
/*     void */
/*     impinge_tot(int i, int l, int r) */
/*     { */
/*  */
/*         return; */
/*     } */
/*     void impinge_tot() { } */
/* }; */

struct sump {
    vector<ll> t;
    vector<ll> p;
    int n;

    sump(int _n) {
        n = _n;
        t.assign(n+1,0);
        p.assign(n+1,0);
    }

    void
    add(int l, int r, int v)
    {
        t[l] += v;
        t[r+1] -= v;
        return;
    }

    void
    gen()
    {
        for (int i = 0; i < n+1; ++i) {
            if (i) p[i] = p[i-1];
            p[i] += t[i];
        }
        return;
    }
};
vi
sub2(vi &c, vi &l, vi &r, vi &v)
{
    int n = sz(c);
    int q = sz(l);

    vi ans;
    sump tr(n);

    for (int j = 0; j < q; ++j) {
        tr.add(l[j], r[j], v[j]);
    }

    tr.gen();

    for (int i = 0; i < n; ++i) {
        ll val = tr.p[i];
        val = max(val,0ll);
        val = min(val,(ll)c[i]);
        ans.pb(val);
    }

    return ans;
}

vi
sub1(vi &c, vi &l, vi &r, vi &v)
{
    int n = sz(c);
    int q = sz(l);

    vi ans;

    ll val;
    for (int i = 0; i < n; ++i) {
        val = 0;
        for (int j = 0; j < q; ++j) {
            if (i < l[j] || i > r[j])
                continue;
            val += (ll)v[j];
            val = min(val,(ll)c[i]);
            val = max(val,0ll);
        }

        ans.pb(val);
    }

    return ans;
}

vi
distribute_candies(vi c, vi l, vi r, vi v)
{
    int n = sz(c);
    int q = sz(l);

    if (n < 3e5 && q < 3e5)
        return sub1(c,l,r,v);

    return sub2(c,l,r,v);

    vi tans;
    for (int i = 0; i < n; ++i)
        tans.pb(69);
    return tans;
}

#ifdef ONPC
void
solve()
{
    int n, q;
    cin >> n >> q;

    vector<int> c(n);
    for (int i = 0; i < n; ++i)
        cin >> c[i];
    
    vector<int> l(q), r(q), v(q);
    for (int i = 0; i < q; ++i)
        cin >> l[i] >> r[i] >> v[i];

    vi ans = distribute_candies(c,l,r,v);

    for (int i = 0; i < sz(ans); ++i) {
        cout << ans[i] << ' ';
    }
    cout << endl;
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        solve();
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 11 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5050 ms 6816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1801 ms 5028 KB Output is correct
3 Correct 869 ms 3952 KB Output is correct
4 Execution timed out 5044 ms 6808 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 861 ms 5032 KB Output is correct
4 Correct 888 ms 3012 KB Output is correct
5 Execution timed out 5082 ms 6676 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 11 ms 368 KB Output is correct
6 Execution timed out 5050 ms 6816 KB Time limit exceeded
7 Halted 0 ms 0 KB -