// #include "candies.h"
#include<bits/stdc++.h>
#include <vector>
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
const int MAXN=2e5;
long long tree[4*MAXN+1];
long long lazy[4*MAXN+1];
vector<int> cc;
vector<int> ans;
vector<int> distribute_candies(vector<int> c, vector<int> ql,
vector<int> qr, vector<int> v) {
int n=c.size();
int q = v.size();
ans.resize(n,0);
cc=c;
ll pre[q+1];
for(int i=0;i<=q;i++) pre[i]=0;
for(int i=0;i<q;i++) pre[i+1]=pre[i]+v[i];
ll sufmax[q+1];
ll sufmin[q+1];
sufmax[q]=pre[q];
sufmin[q]=pre[q];
for(int i=q-1;i>=0;i--){
sufmax[i]=max(pre[i],sufmax[i+1]);
sufmin[i]=min(pre[i],sufmin[i+1]);
}
for(int i=0;i<n;i++){
int l=0;
int r=q+1;
if(sufmax[0]-sufmin[0]<c[i]){
ans[i]=pre[q]-sufmin[0];
continue;
}
while(r-l>1){
int mid=(l+r)/2;
if(sufmax[mid]-sufmin[mid]>c[i]) l=mid;
else r=mid;
}
ll a=pre[l];
ll b=pre[q];
if(a<b){
ll cc=sufmax[l];
ans[i]=c[i]-(cc-b);
}else{
ll cc=sufmin[l];
ans[i]=b-cc;
}
}
return ans;
}
#ifdef IOI
int main() {
int n;
assert(1 == scanf("%d", &n));
std::vector<int> c(n);
for(int i = 0; i < n; ++i) {
assert(scanf("%d", &c[i]) == 1);
}
int q;
assert(1 == scanf("%d", &q));
std::vector<int> l(q), r(q), v(q);
for(int i = 0; i < q; ++i) {
assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
}
std::vector<int> ans = distribute_candies(c, l, r, v);
for(int i = 0; i < n; ++i) {
if (i > 0) {
printf(" ");
}
printf("%d", ans[i]);
}
printf("\n");
fclose(stdout);
return 0;}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
18452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
52 ms |
12260 KB |
Output is correct |
4 |
Correct |
43 ms |
5532 KB |
Output is correct |
5 |
Correct |
97 ms |
17108 KB |
Output is correct |
6 |
Correct |
108 ms |
17700 KB |
Output is correct |
7 |
Correct |
108 ms |
18376 KB |
Output is correct |
8 |
Correct |
97 ms |
16984 KB |
Output is correct |
9 |
Correct |
96 ms |
18484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |