# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
602346 |
2022-07-22T23:09:05 Z |
CyberCow |
Snowball (JOI21_ho_t2) |
C++17 |
|
148 ms |
14012 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
using namespace std;
using ll = long long;
vector<ll> v;
vector<pair<ll, pair<ll, ll>>> p;
ll ans[200005];
void solve()
{
int n, i, j, q;
cin >> n >> q;
ll x, oo = 1000000000000000000LL;
v.push_back(-oo);
for ( i = 0; i < n; i++)
{
cin >> x;
v.push_back(x);
}
v.push_back(oo);
p.push_back({ 0,{ 0, 0 } });
ll tex = 0;
for ( i = 0; i < q; i++)
{
cin >> x;
tex += x;
pair<ll, pair<ll, ll>>anc = p.back();
anc.second.first = max(anc.second.first, tex);
anc.second.second = min(anc.second.second, tex);
anc.first = anc.second.first - anc.second.second;
p.push_back(anc);
}
sort(p.begin(), p.end());
int ind;
for (i = 1; i <= n; i++)
{
ind = lower_bound(p.begin(), p.end(), make_pair(v[i] - v[i - 1], make_pair(0LL, 0LL))) - p.begin();
if (ind == p.size())
ans[i] -= p[ind - 1].second.second;
else
{
if (p[ind].second.second != p[ind - 1].second.second)
ans[i] += v[i] - v[i - 1] - p[ind].second.first;
else
ans[i] += -p[ind].second.second;
}
ind = lower_bound(p.begin(), p.end(), make_pair(v[i + 1] - v[i], make_pair(0LL, 0LL))) - p.begin();
if (ind == p.size())
ans[i] += p[ind - 1].second.first;
else
{
if (p[ind].second.first != p[ind - 1].second.first)
ans[i] += v[i + 1] - v[i] - -p[ind].second.second;
else
ans[i] += p[ind].second.first;
}
}
for ( i = 1; i <= n; i++)
{
cout << ans[i] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:51:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if (ind == p.size())
| ~~~~^~~~~~~~~~~
Main.cpp:61:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if (ind == p.size())
| ~~~~^~~~~~~~~~~
Main.cpp:24:12: warning: unused variable 'j' [-Wunused-variable]
24 | int n, i, j, q;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
472 KB |
Output is correct |
8 |
Correct |
2 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
472 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
472 KB |
Output is correct |
8 |
Correct |
2 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
472 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
33 ms |
8192 KB |
Output is correct |
21 |
Correct |
40 ms |
8056 KB |
Output is correct |
22 |
Correct |
34 ms |
8028 KB |
Output is correct |
23 |
Correct |
28 ms |
7896 KB |
Output is correct |
24 |
Correct |
34 ms |
8156 KB |
Output is correct |
25 |
Correct |
125 ms |
13816 KB |
Output is correct |
26 |
Correct |
145 ms |
13836 KB |
Output is correct |
27 |
Correct |
122 ms |
13584 KB |
Output is correct |
28 |
Correct |
123 ms |
13592 KB |
Output is correct |
29 |
Correct |
148 ms |
13432 KB |
Output is correct |
30 |
Correct |
135 ms |
12972 KB |
Output is correct |
31 |
Correct |
78 ms |
12636 KB |
Output is correct |
32 |
Correct |
79 ms |
12636 KB |
Output is correct |
33 |
Correct |
11 ms |
1836 KB |
Output is correct |
34 |
Correct |
121 ms |
13848 KB |
Output is correct |
35 |
Correct |
141 ms |
13668 KB |
Output is correct |
36 |
Correct |
132 ms |
13860 KB |
Output is correct |
37 |
Correct |
142 ms |
13572 KB |
Output is correct |
38 |
Correct |
126 ms |
13596 KB |
Output is correct |
39 |
Correct |
131 ms |
13620 KB |
Output is correct |
40 |
Correct |
83 ms |
13552 KB |
Output is correct |
41 |
Correct |
43 ms |
8672 KB |
Output is correct |
42 |
Correct |
79 ms |
12552 KB |
Output is correct |
43 |
Correct |
92 ms |
13744 KB |
Output is correct |
44 |
Correct |
35 ms |
8508 KB |
Output is correct |
45 |
Correct |
70 ms |
13644 KB |
Output is correct |
46 |
Correct |
89 ms |
13868 KB |
Output is correct |
47 |
Correct |
90 ms |
14012 KB |
Output is correct |
48 |
Correct |
95 ms |
13888 KB |
Output is correct |