# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
413003 |
2021-05-28T01:33:57 Z |
joseacaz |
Snowball (JOI21_ho_t2) |
C++17 |
|
134 ms |
18244 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
const int MAXN = (int)2e5 + 5;
const ll INF = (1LL << 62LL);
int N, Q;
ll a[MAXN], W[MAXN];
pair<ll, int> spacesL[MAXN], spacesR[MAXN];
ll l[MAXN], r[MAXN], pos;
ll finalL[MAXN], finalR[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
for(int i = 1; i <= N; i++)
cin >> a[i];
a[0] = -INF, a[N + 1] = INF;
for(int i = 0; i <= N + 1; i++)
{
if(i < N + 1)
spacesR[i] = {a[i + 1] - a[i], i};
else
spacesR[i] = {0, N + 1};
if(i > 0)
spacesL[i] = {a[i] - a[i - 1], i};
else
spacesL[i] = {0, 0};
}
sort(spacesR, spacesR + N + 2);
sort(spacesL, spacesL + N + 2);
ll delta = 0;
int lpnt = 0, rpnt = 0;
for(int q = 1; q <= Q; q++)
{
cin >> W[q];
pos += W[q];
l[q] = min(l[q - 1], pos);
r[q] = max(r[q - 1], pos);
if(l[q] < l[q - 1])
{
//cerr << l[q] << " " << r[q] << "\n";
delta += l[q - 1] - l[q];
for(; lpnt <= N + 1; lpnt++)
{
if(spacesL[lpnt].second == 0)
continue;
if(spacesL[lpnt].first > delta)
break;
int idx = spacesL[lpnt].second;
finalL[idx] = a[idx] + l[q - 1] - (spacesL[lpnt].first - (delta - l[q - 1] + l[q]));
//cerr << "l " << idx << ": " << finalL[idx] << "\n";
}
for(; rpnt <= N + 1; rpnt++)
{
if(spacesR[rpnt].second == N + 1)
continue;
if(spacesR[rpnt].first > delta)
break;
int idx = spacesR[rpnt].second;
finalR[idx] = a[idx] + r[q - 1];
//cerr << "r " << idx << ": " << finalR[idx] << "\n";
}
}
else if(r[q] > r[q - 1])
{
//cerr << l[q] << " " << r[q] << "\n";
delta += r[q] - r[q - 1];
for(; lpnt <= N + 1; lpnt++)
{
if(spacesL[lpnt].second == 0)
continue;
if(spacesL[lpnt].first > delta)
break;
int idx = spacesL[lpnt].second;
finalL[idx] = a[idx] + l[q - 1];
//cerr << "l " << idx << ": " << finalL[idx] << "\n";
}
for(; rpnt <= N + 1; rpnt++)
{
if(spacesR[rpnt].second == N + 1)
continue;
if(spacesR[rpnt].first > delta)
break;
int idx = spacesR[rpnt].second;
finalR[idx] = a[idx] + r[q - 1] + (spacesR[rpnt].first - (delta - r[q] + r[q - 1]));
//cerr << "r " << idx << ": " << finalR[idx] << "\n";
}
}
}
for(int i = lpnt; i <= N + 1; i++)
{
int idx = spacesL[i].second;
finalL[idx] = a[idx] + l[Q];
}
for(int i = rpnt; i <= N + 1; i++)
{
int idx = spacesR[i].second;
finalR[idx] = a[idx] + r[Q];
}
for(int i = 1; i <= N; i++)
cout << finalR[i] - finalL[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
36 ms |
5004 KB |
Output is correct |
21 |
Correct |
34 ms |
4924 KB |
Output is correct |
22 |
Correct |
34 ms |
4960 KB |
Output is correct |
23 |
Correct |
31 ms |
5060 KB |
Output is correct |
24 |
Correct |
38 ms |
6852 KB |
Output is correct |
25 |
Correct |
129 ms |
18080 KB |
Output is correct |
26 |
Correct |
127 ms |
18040 KB |
Output is correct |
27 |
Correct |
124 ms |
17848 KB |
Output is correct |
28 |
Correct |
124 ms |
17808 KB |
Output is correct |
29 |
Correct |
124 ms |
17672 KB |
Output is correct |
30 |
Correct |
120 ms |
17248 KB |
Output is correct |
31 |
Correct |
114 ms |
16836 KB |
Output is correct |
32 |
Correct |
83 ms |
16780 KB |
Output is correct |
33 |
Correct |
15 ms |
2500 KB |
Output is correct |
34 |
Correct |
124 ms |
18040 KB |
Output is correct |
35 |
Correct |
119 ms |
17784 KB |
Output is correct |
36 |
Correct |
124 ms |
17988 KB |
Output is correct |
37 |
Correct |
134 ms |
17760 KB |
Output is correct |
38 |
Correct |
128 ms |
17796 KB |
Output is correct |
39 |
Correct |
124 ms |
17776 KB |
Output is correct |
40 |
Correct |
124 ms |
17764 KB |
Output is correct |
41 |
Correct |
43 ms |
5496 KB |
Output is correct |
42 |
Correct |
109 ms |
16864 KB |
Output is correct |
43 |
Correct |
119 ms |
17988 KB |
Output is correct |
44 |
Correct |
37 ms |
5536 KB |
Output is correct |
45 |
Correct |
117 ms |
17796 KB |
Output is correct |
46 |
Correct |
112 ms |
18244 KB |
Output is correct |
47 |
Correct |
112 ms |
18096 KB |
Output is correct |
48 |
Correct |
113 ms |
18112 KB |
Output is correct |