#include "candies.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
long long tree[1000005];
void add(int r, int v){
r++;
for(;r<400005;r+=r&-r)
tree[r]+=v;
}
void add(int l, int r, int v){
add(r,v);
if(l-1>=0)
add(l-1,v);
}
int get(int x){
x++;
int sum=0;
for(;x>0;x-=x&-x)
sum+=tree[x];
return sum;
}
int get(int r, int val){
return get(r)-(r>0?get(r-1):0);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n=c.size(),q=v.size();
vector<int> a(n);
if(n<=2000 && q<=2000){
for(int t=0;t<q;t++){
for(int i=l[t];i<=r[t];i++){
a[i]+=v[t];
a[i]=min(c[i],a[i]);
a[i]=max(a[i],0);
}
}
}
else{
for(int t=0;t<q;t++){
add(l[t],r[t],v[t]);
}
for(int i=0;i<n;i++)
a[i]=max(c[i],get(i,0));
}
return a;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
94 ms |
8956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
52 ms |
4960 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
54 ms |
4968 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Incorrect |
94 ms |
8956 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |