# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
651181 |
2022-10-17T15:28:43 Z |
bicsi |
Fire (JOI20_ho_t5) |
C++14 |
|
467 ms |
31004 KB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q; cin >> n >> q;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
vector<int> len[2];
for (int rev = 0; rev < 2; ++rev) {
vector<int> stk = {-1};
for (int i = 0; i < n; ++i) {
while (stk.size() > 1 && v[i] + rev > v[stk.back()])
stk.pop_back();
len[rev].push_back(i - stk.back());
stk.push_back(i);
}
reverse(v.begin(), v.end());
}
reverse(len[1].begin(), len[1].end());
int t = 0;
auto get_range = [&](int i) {
int l = len[0][i] > i ? i : i + max(0, t - len[0][i] + 1);
int r = i + min(t + 1, len[1][i]);
return make_pair(l, r);
};
auto cmp = [&](int i, int j) {
assert(i >= 0);
if (j < 0) {
auto [l, r] = get_range(i);
return r < (~j);
}
return i < j;
};
set<int, decltype(cmp)> S(cmp);
for (int i = 0; i < n; ++i)
S.insert(i);
vector<pair<long long, long long>> fw(n + 1);
auto update = [&](int i, long long k, long long c) {
for (++i; i <= n; i += (i & -i)) {
fw[i].first += k;
fw[i].second += c;
}
};
auto query = [&](int pos) {
int i = *S.lower_bound(~pos);
auto [l, r] = get_range(i);
assert(l <= pos && r >= pos);
long long ans = 1LL * (min(r, pos) - l) * v[i];
for (; i > 0; i -= (i & -i))
ans += fw[i].first * t + fw[i].second;
return ans;
};
for (int i = 0; i < n; ++i)
update(i, v[i], v[i]);
vector<tuple<int, int, int>> evs;
for (int i = 0; i < n; ++i) {
evs.emplace_back(len[1][i] - 1, 0, i);
if (len[0][i] <= i) {
evs.emplace_back(len[0][i] - 1, 0, i);
evs.emplace_back(len[0][i] + len[1][i] - 1, 1, i);
}
}
vector<pair<int, int>> qs(q);
for (int i = 0; i < q; ++i) {
int t, l, r; cin >> t >> l >> r;
qs[i] = {l - 1, r};
evs.emplace_back(t, 2, i);
}
sort(evs.begin(), evs.end());
vector<long long> ans(q);
for (auto& [t_, typ, i] : evs) {
t = t_;
if (typ == 0) { // decrease slope
update(i, -v[i], 1LL * t * v[i]);
} else if (typ == 1) { // erase
S.erase(i);
update(i, v[i], -1LL * t * v[i]);
} else { // query
auto [l, r] = qs[i];
ans[i] = query(r) - query(l);
}
}
for (int i = 0; i < q; ++i)
cout << ans[i] << '\n';
return 0;
}
Compilation message
ho_t5.cpp: In lambda function:
ho_t5.cpp:35:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | auto [l, r] = get_range(i);
| ^
ho_t5.cpp: In lambda function:
ho_t5.cpp:53:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | auto [l, r] = get_range(i);
| ^
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:79:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
79 | for (auto& [t_, typ, i] : evs) {
| ^
ho_t5.cpp:87:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
87 | auto [l, r] = qs[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
298 ms |
30628 KB |
Output is correct |
3 |
Correct |
294 ms |
30360 KB |
Output is correct |
4 |
Correct |
312 ms |
30620 KB |
Output is correct |
5 |
Correct |
325 ms |
30916 KB |
Output is correct |
6 |
Correct |
323 ms |
30536 KB |
Output is correct |
7 |
Correct |
311 ms |
30968 KB |
Output is correct |
8 |
Correct |
315 ms |
31004 KB |
Output is correct |
9 |
Correct |
317 ms |
30972 KB |
Output is correct |
10 |
Correct |
302 ms |
30124 KB |
Output is correct |
11 |
Correct |
309 ms |
30932 KB |
Output is correct |
12 |
Correct |
286 ms |
30120 KB |
Output is correct |
13 |
Correct |
335 ms |
30792 KB |
Output is correct |
14 |
Correct |
323 ms |
30648 KB |
Output is correct |
15 |
Correct |
320 ms |
30768 KB |
Output is correct |
16 |
Correct |
312 ms |
30504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
313 ms |
29724 KB |
Output is correct |
3 |
Correct |
326 ms |
29276 KB |
Output is correct |
4 |
Correct |
325 ms |
30252 KB |
Output is correct |
5 |
Correct |
320 ms |
29624 KB |
Output is correct |
6 |
Correct |
322 ms |
29804 KB |
Output is correct |
7 |
Correct |
325 ms |
29888 KB |
Output is correct |
8 |
Correct |
327 ms |
29652 KB |
Output is correct |
9 |
Correct |
336 ms |
29420 KB |
Output is correct |
10 |
Correct |
307 ms |
29140 KB |
Output is correct |
11 |
Correct |
321 ms |
30228 KB |
Output is correct |
12 |
Correct |
327 ms |
29944 KB |
Output is correct |
13 |
Correct |
307 ms |
30140 KB |
Output is correct |
14 |
Correct |
308 ms |
29508 KB |
Output is correct |
15 |
Correct |
309 ms |
30156 KB |
Output is correct |
16 |
Correct |
322 ms |
29836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
28656 KB |
Output is correct |
2 |
Correct |
430 ms |
28828 KB |
Output is correct |
3 |
Correct |
423 ms |
29436 KB |
Output is correct |
4 |
Correct |
408 ms |
28668 KB |
Output is correct |
5 |
Correct |
399 ms |
28716 KB |
Output is correct |
6 |
Correct |
421 ms |
28920 KB |
Output is correct |
7 |
Correct |
397 ms |
29216 KB |
Output is correct |
8 |
Correct |
393 ms |
29064 KB |
Output is correct |
9 |
Correct |
412 ms |
28688 KB |
Output is correct |
10 |
Correct |
467 ms |
29064 KB |
Output is correct |
11 |
Correct |
415 ms |
29028 KB |
Output is correct |
12 |
Correct |
405 ms |
28916 KB |
Output is correct |
13 |
Correct |
405 ms |
28800 KB |
Output is correct |
14 |
Correct |
419 ms |
28900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
298 ms |
30628 KB |
Output is correct |
34 |
Correct |
294 ms |
30360 KB |
Output is correct |
35 |
Correct |
312 ms |
30620 KB |
Output is correct |
36 |
Correct |
325 ms |
30916 KB |
Output is correct |
37 |
Correct |
323 ms |
30536 KB |
Output is correct |
38 |
Correct |
311 ms |
30968 KB |
Output is correct |
39 |
Correct |
315 ms |
31004 KB |
Output is correct |
40 |
Correct |
317 ms |
30972 KB |
Output is correct |
41 |
Correct |
302 ms |
30124 KB |
Output is correct |
42 |
Correct |
309 ms |
30932 KB |
Output is correct |
43 |
Correct |
286 ms |
30120 KB |
Output is correct |
44 |
Correct |
335 ms |
30792 KB |
Output is correct |
45 |
Correct |
323 ms |
30648 KB |
Output is correct |
46 |
Correct |
320 ms |
30768 KB |
Output is correct |
47 |
Correct |
312 ms |
30504 KB |
Output is correct |
48 |
Correct |
313 ms |
29724 KB |
Output is correct |
49 |
Correct |
326 ms |
29276 KB |
Output is correct |
50 |
Correct |
325 ms |
30252 KB |
Output is correct |
51 |
Correct |
320 ms |
29624 KB |
Output is correct |
52 |
Correct |
322 ms |
29804 KB |
Output is correct |
53 |
Correct |
325 ms |
29888 KB |
Output is correct |
54 |
Correct |
327 ms |
29652 KB |
Output is correct |
55 |
Correct |
336 ms |
29420 KB |
Output is correct |
56 |
Correct |
307 ms |
29140 KB |
Output is correct |
57 |
Correct |
321 ms |
30228 KB |
Output is correct |
58 |
Correct |
327 ms |
29944 KB |
Output is correct |
59 |
Correct |
307 ms |
30140 KB |
Output is correct |
60 |
Correct |
308 ms |
29508 KB |
Output is correct |
61 |
Correct |
309 ms |
30156 KB |
Output is correct |
62 |
Correct |
322 ms |
29836 KB |
Output is correct |
63 |
Correct |
397 ms |
28656 KB |
Output is correct |
64 |
Correct |
430 ms |
28828 KB |
Output is correct |
65 |
Correct |
423 ms |
29436 KB |
Output is correct |
66 |
Correct |
408 ms |
28668 KB |
Output is correct |
67 |
Correct |
399 ms |
28716 KB |
Output is correct |
68 |
Correct |
421 ms |
28920 KB |
Output is correct |
69 |
Correct |
397 ms |
29216 KB |
Output is correct |
70 |
Correct |
393 ms |
29064 KB |
Output is correct |
71 |
Correct |
412 ms |
28688 KB |
Output is correct |
72 |
Correct |
467 ms |
29064 KB |
Output is correct |
73 |
Correct |
415 ms |
29028 KB |
Output is correct |
74 |
Correct |
405 ms |
28916 KB |
Output is correct |
75 |
Correct |
405 ms |
28800 KB |
Output is correct |
76 |
Correct |
419 ms |
28900 KB |
Output is correct |
77 |
Correct |
325 ms |
30124 KB |
Output is correct |
78 |
Correct |
326 ms |
30624 KB |
Output is correct |
79 |
Correct |
319 ms |
30500 KB |
Output is correct |
80 |
Correct |
310 ms |
30112 KB |
Output is correct |
81 |
Correct |
318 ms |
29980 KB |
Output is correct |
82 |
Correct |
324 ms |
30356 KB |
Output is correct |
83 |
Correct |
334 ms |
30208 KB |
Output is correct |
84 |
Correct |
317 ms |
29936 KB |
Output is correct |
85 |
Correct |
318 ms |
30656 KB |
Output is correct |
86 |
Correct |
319 ms |
30268 KB |
Output is correct |
87 |
Correct |
352 ms |
30752 KB |
Output is correct |
88 |
Correct |
356 ms |
30672 KB |
Output is correct |
89 |
Correct |
332 ms |
29772 KB |
Output is correct |
90 |
Correct |
351 ms |
30508 KB |
Output is correct |
91 |
Correct |
345 ms |
29972 KB |
Output is correct |
92 |
Correct |
355 ms |
29864 KB |
Output is correct |
93 |
Correct |
371 ms |
30096 KB |
Output is correct |
94 |
Correct |
367 ms |
30928 KB |
Output is correct |
95 |
Correct |
325 ms |
30784 KB |
Output is correct |
96 |
Correct |
306 ms |
30272 KB |
Output is correct |
97 |
Correct |
320 ms |
30304 KB |
Output is correct |
98 |
Correct |
337 ms |
29996 KB |
Output is correct |
99 |
Correct |
332 ms |
30272 KB |
Output is correct |
100 |
Correct |
341 ms |
30268 KB |
Output is correct |
101 |
Correct |
347 ms |
30040 KB |
Output is correct |
102 |
Correct |
337 ms |
30364 KB |
Output is correct |