#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
const ll INF = 1e18;
struct Query
{
int l, r, v;
};
int N, Q;
int A[MAXN+10];
Query B[MAXN+10];
int ans[MAXN+10];
vector<int> distribute_candies(vector<int> _C, vector<int> _L, vector<int> _R, vector<int> _V)
{
N=_C.size(); Q=_L.size();
for(int i=1; i<=N; i++) A[i]=_C[i-1];
for(int i=1; i<=Q; i++) B[i]={_L[i-1]+1, _R[i-1]+1, _V[i-1]};
vector<ll> V;
for(int i=1; i<=Q; i++)
{
if(B[i].v>0)
{
ll x=0, y=0;
while(!V.empty())
{
ll x2, y2;
x2=V.back();
if(V.size()%2) // /
{
y2=x2-x+y;
}
else // --
{
y2=y;
}
if(y2<x2-B[i].v)
{
V.push_back(y2+B[i].v);
break;
}
else
{
V.pop_back();
}
x=x2; y=y2;
}
if(V.empty())
{
V.push_back(y+B[i].v);
}
}
else
{
ll x=0, y=0;
while(!V.empty())
{
ll x2, y2;
x2=V.back();
if(V.size()%2) // /
{
y2=x2-x+y;
}
else // --
{
y2=y;
}
if(y2>-B[i].v)
{
V.push_back(x2-y2-B[i].v);
break;
}
else
{
V.pop_back();
}
x=x2; y=y2;
}
}
//for(auto it : V) printf("%lld ", it); printf("\n");
}
vector<pii> V2;
for(int i=1; i<=N; i++) V2.push_back({A[i], i});
sort(V2.begin(), V2.end());
int pt=0;
ll x=0, y=0;
while(!V.empty())
{
ll x2, y2;
x2=V.back();
if(V.size()%2) // /
{
y2=x2-x+y;
}
else // --
{
y2=y;
}
for(; pt<V2.size() && V2[pt].first<=x2; pt++)
{
if(V.size()%2) // /
{
ans[V2[pt].second]=y2-x2+V2[pt].first;
}
else // --
{
ans[V2[pt].second]=y2;
}
}
V.pop_back();
x=x2; y=y2;
}
for(; pt<V2.size(); pt++)
{
ans[V2[pt].second]=y;
}
return vector<int>(ans+1, ans+N+1);
}
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:111:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for(; pt<V2.size() && V2[pt].first<=x2; pt++)
| ~~^~~~~~~~~~
candies.cpp:126:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | for(; pt<V2.size(); pt++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
162 ms |
12724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
67 ms |
9604 KB |
Output is correct |
4 |
Correct |
93 ms |
6964 KB |
Output is correct |
5 |
Correct |
143 ms |
16168 KB |
Output is correct |
6 |
Correct |
150 ms |
17052 KB |
Output is correct |
7 |
Correct |
159 ms |
17588 KB |
Output is correct |
8 |
Correct |
140 ms |
16180 KB |
Output is correct |
9 |
Correct |
133 ms |
17720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |