Submission #814628

#TimeUsernameProblemLanguageResultExecution timeMemory
814628gesghaDistributing Candies (IOI21_candies)C++17
3 / 100
78 ms12124 KiB
#include "candies.h"
#include <bits/stdc++.h>
 
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
 
#define fi first
#define se second
#define pb push_back
 
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
 
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ve = vector <T>;
 
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
 
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
 
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
 
const int oo = 1e9;
const ll OO = 1e18;
const int N = 2e5 + 10;
const int M = 5e3 + 100;
const int mod = 1e9 + 7;
const bool TEST = 0;


int T[4 * N];


void push(int v) {
    if(!T[v]) return;
    T[v << 1] += T[v];
    T[v << 1 | 1] += T[v];
    T[v] = 0;
}

void add(int v, int tl, int tr, int l, int r, int x) {
    if (l > r) return;
    if (l == tl && r == tr) {
        T[v] += x;
        return;
    }
    push(v);
    int tm = (tl + tr) >> 1;
    add(v << 1, tl, tm, l, min(r, tm), x);
    add(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r, x);
}

vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = v.size();
    bool ok = 1;
    bool ok1 = 1;
    for (int i = 0; i < q; i++) ok &= (v[i] > 0);
    for (int i = 0; i < q; i++) ok1 &= (c[i] == c[0]);
    vector<int> s(n);
    if (n <= 2000 && q <= 2000) {
        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                s[j] += v[i];
                umx(s[j], 0);
                umn(s[j], c[j]);
            }
        }
        return s;
    }
    return s;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...