# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059494 | pcc | Distributing Candies (IOI21_candies) | C++17 | 73 ms | 13652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "candies.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long
int N,Q;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
N = c.size();
Q = v.size();
if(N*Q<=1e7){
vector<int> ans(N,0);
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(ans[j]+v[i],0);
}
}
return ans;
}
else if(*min_element(v.begin(),v.end())>=0){
vector<ll> dif(N+1,0);
for(int i = 0;i<Q;i++){
dif[l[i]] += v[i];
dif[r[i]+1] -= v[i];
}
for(int i = 1;i<dif.size();i++)dif[i] += dif[i-1];
vector<int> ans(N);
for(int i = 0;i<N;i++)ans[i] = min(1ll*c[i],dif[i]);
return ans;
}
assert(false);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |