#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<vi>
using ll=long long;
#define vl vector<long long>
ll np(int n){
while(n & (n-1))n++;
return n;
}
vl segtree;
void update(ll pos, ll l, ll r, ll x, ll y, ll value){
if(y<l)return;
if(x>r)return;
if(l>=x && r<=y){
segtree[pos]+=value;
return;
}
update(pos*2,l,(l+r)/2,x,y,value);
update(pos*2+1,(l+r)/2+1,r,x,y,value);
}
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();
int q=l.size();
int N=np(n);
segtree.resize(2*N);
std::vector<int> s(n);
for(int i=0;i<q;i++
){
int x=l[i];
int y=r[i];
update(1,0,N-1,x,y,v[i]);
}
for(int i=1;i<N;i++){
segtree[2*i]+=segtree[i];
segtree[2*i+1]+=segtree[i];
}
for(int i=0;i<n;i++){
s[i]=min(segtree[N+i],ll(c[i]));
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
11376 KB |
Output is correct |
2 |
Correct |
129 ms |
15536 KB |
Output is correct |
3 |
Correct |
134 ms |
15448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |