#include"candies.h"
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int n,days;
vector<int>vec;
void tree_init(){
vec.resize(days);
}
void tree_add(int pos,int val){
//for(int i=pos;i<days;i++)
vec[pos]+=val;
}
int tree_get(int bound){
int curr=0;
for(int i=0;i<days;i++){
curr+=vec[i];
curr=max(0,min(bound,curr));
}
return curr;
}
vector<int>distribute_candies(vector<int>c,vector<int>l,vector<int>r,vector<int>v){
n=(int)c.size();
days=(int)v.size();
vector<vector<pair<int,int>>>events;
events.resize(n+1);
for(int i=0;i<days;i++){
events[l[i]].push_back({i,v[i]});
events[r[i]+1].push_back({i,-v[i]});
}
vector<int>s(n);
tree_init();
for(int i=0;i<n;i++){
for(auto event:events[i])
tree_add(event.first,event.second);
s[i]=tree_get(c[i]);
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5045 ms |
19812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
786 ms |
13348 KB |
Output is correct |
3 |
Correct |
776 ms |
9716 KB |
Output is correct |
4 |
Execution timed out |
5048 ms |
25764 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
785 ms |
11620 KB |
Output is correct |
4 |
Correct |
775 ms |
8680 KB |
Output is correct |
5 |
Execution timed out |
5026 ms |
19372 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
468 KB |
Output is correct |
6 |
Execution timed out |
5045 ms |
19812 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |