Submission #828711

#TimeUsernameProblemLanguageResultExecution timeMemory
828711fatemetmhrDistributing Candies (IOI21_candies)C++17
38 / 100
5051 ms9268 KiB
//#pragma GCC optimize ("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops,O3")

#include "candies.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define debug(x)  cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)    x.begin(), x.end()
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define fi        first
#define se        second
#define pb        push_back
#define mp        make_pair

const int ss    = 1000;
const int maxn5 = 2e5 + 10;

int ret[maxn5], c[maxn5];

std::vector<int> distribute_candies(std::vector<int> C, std::vector<int> L,
                                    std::vector<int> R, std::vector<int> V) {
    int n = C.size(), q = L.size();
    for(int i = 0; i < n; i++)
        c[i] = C[i];
    for(int tt = 0; tt < n; tt += ss){
        for(int i = 0; i < q; i++){
            int l = MAX(L[i], tt), r = MIN(R[i] + 1, MIN(tt + ss, n)), v = V[i];
            if(v > 0){
                for(int i = l; i < r; i++){
                    ret[i] = MIN(c[i], ret[i] + v);
                }
            }
            else{
                for(int i = l; i < r; i++){
                    ret[i] = MAX(0, ret[i] + v);
                }
            }
        }
    }

    std::vector<int> s;
    for(int i = 0; i < n; i++)
        s.pb(ret[i]);
    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...