Submission #444583

# Submission time Handle Problem Language Result Execution time Memory
444583 2021-07-14T09:52:09 Z KiriLL1ca Distributing Candies (IOI21_candies) C++17
3 / 100
778 ms 14972 KB
#include <bits/stdc++.h>
#define all(X) X.begin(), X.end()
#define rall(X) X.rbegin(), X.rend()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fr first
#define sc second
#define endl '\n'
#define pb push_back
#define pf push_front

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int maxn = 2e5 + 10;

struct SegTree_subtask2 {
    vector <int> t, p;

    void init () {
        t.resize(4 * maxn);
        p.resize(4 * maxn);
    }

    void push (int v) {
        p[2 * v] += p[v];
        p[2 * v + 1] += p[v];
        p[v] = 0;
    }

    void upd (int v, int tl, int tr, int l, int r, int x) {
        if (tl > r || l > tr) {
            return;
        }
        if (l <= tl && tr <= r) {
            p[v] += x;
            return;
        }
        push(v);
        int tm = (tl + tr) >> 1;
        upd(2 * v, tl, tm, l, r, x);
        upd(2 * v + 1, tm + 1, tr, l, r, x);
    }

    int get (int v, int tl, int tr, int pos) {
        if (tl == tr) {
            t[v] += p[v];
            p[v] = 0;
            return t[v];
        }
        else {
            push(v);
            int tm = (tl + tr) >> 1;
            if (pos <= tm) {
                return get(2 * v, tl, tm, pos);
            }
            else {
                return get(2 * v + 1, tm + 1, tr, pos);
            }
        }
    }
};



vector <int> distribute_candies (vector <int> c, vector <int> l, vector <int> r, vector <int> v) {
    int n = sz(c);
    int q = sz(l);
    vector <int> ans (n);

    bool subtask1 = (n <= 3000);
    bool subtask2 = true, subtask3 = true;

    for (int i = 0; i < q; i++) {
        if (v[i] < 0) {
            subtask2 = false;
        }
    }

    for (int i = 1; i < n; i++) {
        if (c[i] != c[0]) {
            subtask3 = false;
        }
    }

    if (subtask1) {
        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                if (v[i] > 0) {
                    ans[j] = min(ans[j] + v[i], c[j]);
                }
                else {
                    ans[j] = max(0, ans[j] + v[i]);
                }
            }
        }
        return ans;
    }
    if (subtask2) {
        SegTree_subtask2 st; st.init();
        for (int i = 0; i < q; i++) {
            st.upd(1, 0, n - 1, l[i], r[i], v[i]);
        }
        for (int i = 0; i < n; i++) {
            ans[i] = st.get(1, 0, n - 1, i);
            if (ans[i] > c[i]) {
                ans[i] = c[i];
            }
        }
        return ans;
    }

}
/*
int32_t main ()
{
    int n, q; cin >> n >> q;
    vector <int> c (n), l (q), r(q), v(q);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> v[i];
    }
    vector <int> w = distribute_candies(c, l, r, v);
    for (auto i : w) {
        cout << i << " ";
    }
	return 0;
}*/

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:81:27: warning: variable 'subtask3' set but not used [-Wunused-but-set-variable]
   81 |     bool subtask2 = true, subtask3 = true;
      |                           ^~~~~~~~
candies.cpp:122:1: warning: control reaches end of non-void function [-Wreturn-type]
  122 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 266 ms 14972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 156 ms 6296 KB Output is correct
3 Incorrect 88 ms 10304 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 778 ms 6364 KB Output is correct
4 Incorrect 83 ms 10052 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Incorrect 266 ms 14972 KB Output isn't correct
7 Halted 0 ms 0 KB -