# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
532826 |
2022-03-04T03:17:03 Z |
amunduzbaev |
Fire (JOI20_ho_t5) |
C++17 |
|
577 ms |
51204 KB |
#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int N = 2e5 + 5;
struct ST{
int tree[N << 2];
void add(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x] += v;
return;
} int m = (lx + rx) >> 1;
add(l, r, v, lx, m, x<<1), add(l, r, v, m+1, rx, x<<1|1);
}
int get(int i, int lx = 0, int rx = N, int x = 1){
if(lx == rx) return tree[x];
int m = (lx + rx) >> 1;
if(i <= m) return get(i, lx, m, x<<1) + tree[x];
else return get(i, m+1, rx, x<<1|1) + tree[x];
}
}tree, cnt;
int s[N], t[N], L[N], R[N];
int l[N], r[N], res[N];
vector<int> par[N], qq[N], q2[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, q; cin>>n>>q;
for(int i=1;i<=n;i++) cin>>s[i];
for(int i=1;i<=q;i++){
cin>>t[i]>>L[i]>>R[i];
qq[R[i]].push_back(i);
qq[L[i] - 1].push_back(-i);
}
vector<int> ss;
for(int i=n;i>0;i--){
while(!ss.empty() && s[ss.back()] <= s[i]) ss.pop_back();
if(!ss.empty()) r[i] = ss.back() - 1; //, par[ss.back()].push_back(i);
else r[i] = n;
ss.push_back(i);
} ss.clear();
for(int i=1;i<=n;i++){
while(!ss.empty() && s[ss.back()] < s[i]) ss.pop_back();
if(!ss.empty()) l[i] = ss.back() + 1;
else l[i] = 1;
ss.push_back(i);
for(auto j : qq[i]){
int p = *lower_bound(ss.begin(), ss.end(), i - t[abs(j)]);
int add = s[p] * (i - max(p, (l[p] > 1 ? l[p] + t[abs(j)] : 0)) + 1);
if(j < 0) res[-j] -= add;
else res[j] += add;
q2[p - 1].push_back(j);
}
}
//~ cout<<res[1]<<"\n";
for(int i=1;i<=n;i++){
int MX = r[i] - (l[i] > 1 ? l[i] : -N + r[i]);
tree.add(0, r[i] - i - 1, i * s[i]);
cnt.add(0, r[i] - i - 1, s[i]);
tree.add(r[i] - i, MX, r[i] * s[i]);
if(l[i] > 1){
tree.add(0, i - l[i], -i * s[i]);
tree.add(i - l[i] + 1, MX, -l[i] * s[i]);
cnt.add(i - l[i] + 1, MX, -s[i]);
} else {
tree.add(0, MX, -i * s[i]);
} tree.add(0, MX, s[i]);
for(auto j : q2[i]){
if(j > 0){
res[j] += (tree.get(t[j]) + cnt.get(t[j]) * t[j]);
}
else {
j = -j, res[j] -= (tree.get(t[j]) + cnt.get(t[j]) * t[j]);
}
}
}
for(int i=1;i<=q;i++) cout<<res[i]<<"\n";
}
/*
10 1
3 1 4 1 5 9 2 6 5 3
4 2 7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
11 ms |
14532 KB |
Output is correct |
3 |
Correct |
9 ms |
14540 KB |
Output is correct |
4 |
Correct |
8 ms |
14540 KB |
Output is correct |
5 |
Correct |
9 ms |
14540 KB |
Output is correct |
6 |
Correct |
8 ms |
14576 KB |
Output is correct |
7 |
Correct |
8 ms |
14540 KB |
Output is correct |
8 |
Correct |
8 ms |
14540 KB |
Output is correct |
9 |
Correct |
9 ms |
14540 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
11 |
Correct |
10 ms |
14540 KB |
Output is correct |
12 |
Correct |
9 ms |
14540 KB |
Output is correct |
13 |
Correct |
9 ms |
14516 KB |
Output is correct |
14 |
Correct |
10 ms |
14540 KB |
Output is correct |
15 |
Correct |
8 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14476 KB |
Output is correct |
17 |
Correct |
10 ms |
14536 KB |
Output is correct |
18 |
Correct |
8 ms |
14544 KB |
Output is correct |
19 |
Correct |
11 ms |
14508 KB |
Output is correct |
20 |
Correct |
9 ms |
14540 KB |
Output is correct |
21 |
Correct |
8 ms |
14488 KB |
Output is correct |
22 |
Correct |
10 ms |
14540 KB |
Output is correct |
23 |
Correct |
8 ms |
14556 KB |
Output is correct |
24 |
Correct |
11 ms |
14540 KB |
Output is correct |
25 |
Correct |
9 ms |
14644 KB |
Output is correct |
26 |
Correct |
8 ms |
14536 KB |
Output is correct |
27 |
Correct |
9 ms |
14536 KB |
Output is correct |
28 |
Correct |
8 ms |
14540 KB |
Output is correct |
29 |
Correct |
9 ms |
14540 KB |
Output is correct |
30 |
Correct |
9 ms |
14540 KB |
Output is correct |
31 |
Correct |
9 ms |
14540 KB |
Output is correct |
32 |
Correct |
10 ms |
14528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
387 ms |
44660 KB |
Output is correct |
3 |
Correct |
316 ms |
44644 KB |
Output is correct |
4 |
Correct |
317 ms |
45696 KB |
Output is correct |
5 |
Correct |
322 ms |
45460 KB |
Output is correct |
6 |
Correct |
289 ms |
44736 KB |
Output is correct |
7 |
Correct |
323 ms |
45936 KB |
Output is correct |
8 |
Correct |
317 ms |
45188 KB |
Output is correct |
9 |
Correct |
372 ms |
45912 KB |
Output is correct |
10 |
Correct |
334 ms |
45012 KB |
Output is correct |
11 |
Correct |
330 ms |
45084 KB |
Output is correct |
12 |
Correct |
291 ms |
44368 KB |
Output is correct |
13 |
Correct |
420 ms |
44652 KB |
Output is correct |
14 |
Correct |
314 ms |
44592 KB |
Output is correct |
15 |
Correct |
297 ms |
44960 KB |
Output is correct |
16 |
Correct |
306 ms |
45260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
390 ms |
44500 KB |
Output is correct |
3 |
Correct |
348 ms |
43828 KB |
Output is correct |
4 |
Correct |
366 ms |
44828 KB |
Output is correct |
5 |
Correct |
346 ms |
43872 KB |
Output is correct |
6 |
Correct |
368 ms |
44308 KB |
Output is correct |
7 |
Correct |
386 ms |
44132 KB |
Output is correct |
8 |
Correct |
389 ms |
44264 KB |
Output is correct |
9 |
Correct |
389 ms |
44124 KB |
Output is correct |
10 |
Correct |
394 ms |
43988 KB |
Output is correct |
11 |
Correct |
384 ms |
44576 KB |
Output is correct |
12 |
Correct |
379 ms |
43664 KB |
Output is correct |
13 |
Correct |
369 ms |
44916 KB |
Output is correct |
14 |
Correct |
378 ms |
44228 KB |
Output is correct |
15 |
Correct |
360 ms |
44304 KB |
Output is correct |
16 |
Correct |
363 ms |
44116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
513 ms |
50164 KB |
Output is correct |
2 |
Correct |
491 ms |
50148 KB |
Output is correct |
3 |
Correct |
521 ms |
51204 KB |
Output is correct |
4 |
Correct |
517 ms |
50764 KB |
Output is correct |
5 |
Correct |
567 ms |
50596 KB |
Output is correct |
6 |
Correct |
452 ms |
50072 KB |
Output is correct |
7 |
Correct |
494 ms |
50680 KB |
Output is correct |
8 |
Correct |
512 ms |
50736 KB |
Output is correct |
9 |
Correct |
501 ms |
50528 KB |
Output is correct |
10 |
Correct |
478 ms |
50420 KB |
Output is correct |
11 |
Correct |
577 ms |
50844 KB |
Output is correct |
12 |
Correct |
521 ms |
50844 KB |
Output is correct |
13 |
Correct |
542 ms |
50636 KB |
Output is correct |
14 |
Correct |
478 ms |
50888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
11 ms |
14532 KB |
Output is correct |
3 |
Correct |
9 ms |
14540 KB |
Output is correct |
4 |
Correct |
8 ms |
14540 KB |
Output is correct |
5 |
Correct |
9 ms |
14540 KB |
Output is correct |
6 |
Correct |
8 ms |
14576 KB |
Output is correct |
7 |
Correct |
8 ms |
14540 KB |
Output is correct |
8 |
Correct |
8 ms |
14540 KB |
Output is correct |
9 |
Correct |
9 ms |
14540 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
11 |
Correct |
10 ms |
14540 KB |
Output is correct |
12 |
Correct |
9 ms |
14540 KB |
Output is correct |
13 |
Correct |
9 ms |
14516 KB |
Output is correct |
14 |
Correct |
10 ms |
14540 KB |
Output is correct |
15 |
Correct |
8 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14476 KB |
Output is correct |
17 |
Correct |
10 ms |
14536 KB |
Output is correct |
18 |
Correct |
8 ms |
14544 KB |
Output is correct |
19 |
Correct |
11 ms |
14508 KB |
Output is correct |
20 |
Correct |
9 ms |
14540 KB |
Output is correct |
21 |
Correct |
8 ms |
14488 KB |
Output is correct |
22 |
Correct |
10 ms |
14540 KB |
Output is correct |
23 |
Correct |
8 ms |
14556 KB |
Output is correct |
24 |
Correct |
11 ms |
14540 KB |
Output is correct |
25 |
Correct |
9 ms |
14644 KB |
Output is correct |
26 |
Correct |
8 ms |
14536 KB |
Output is correct |
27 |
Correct |
9 ms |
14536 KB |
Output is correct |
28 |
Correct |
8 ms |
14540 KB |
Output is correct |
29 |
Correct |
9 ms |
14540 KB |
Output is correct |
30 |
Correct |
9 ms |
14540 KB |
Output is correct |
31 |
Correct |
9 ms |
14540 KB |
Output is correct |
32 |
Correct |
10 ms |
14528 KB |
Output is correct |
33 |
Correct |
387 ms |
44660 KB |
Output is correct |
34 |
Correct |
316 ms |
44644 KB |
Output is correct |
35 |
Correct |
317 ms |
45696 KB |
Output is correct |
36 |
Correct |
322 ms |
45460 KB |
Output is correct |
37 |
Correct |
289 ms |
44736 KB |
Output is correct |
38 |
Correct |
323 ms |
45936 KB |
Output is correct |
39 |
Correct |
317 ms |
45188 KB |
Output is correct |
40 |
Correct |
372 ms |
45912 KB |
Output is correct |
41 |
Correct |
334 ms |
45012 KB |
Output is correct |
42 |
Correct |
330 ms |
45084 KB |
Output is correct |
43 |
Correct |
291 ms |
44368 KB |
Output is correct |
44 |
Correct |
420 ms |
44652 KB |
Output is correct |
45 |
Correct |
314 ms |
44592 KB |
Output is correct |
46 |
Correct |
297 ms |
44960 KB |
Output is correct |
47 |
Correct |
306 ms |
45260 KB |
Output is correct |
48 |
Correct |
390 ms |
44500 KB |
Output is correct |
49 |
Correct |
348 ms |
43828 KB |
Output is correct |
50 |
Correct |
366 ms |
44828 KB |
Output is correct |
51 |
Correct |
346 ms |
43872 KB |
Output is correct |
52 |
Correct |
368 ms |
44308 KB |
Output is correct |
53 |
Correct |
386 ms |
44132 KB |
Output is correct |
54 |
Correct |
389 ms |
44264 KB |
Output is correct |
55 |
Correct |
389 ms |
44124 KB |
Output is correct |
56 |
Correct |
394 ms |
43988 KB |
Output is correct |
57 |
Correct |
384 ms |
44576 KB |
Output is correct |
58 |
Correct |
379 ms |
43664 KB |
Output is correct |
59 |
Correct |
369 ms |
44916 KB |
Output is correct |
60 |
Correct |
378 ms |
44228 KB |
Output is correct |
61 |
Correct |
360 ms |
44304 KB |
Output is correct |
62 |
Correct |
363 ms |
44116 KB |
Output is correct |
63 |
Correct |
513 ms |
50164 KB |
Output is correct |
64 |
Correct |
491 ms |
50148 KB |
Output is correct |
65 |
Correct |
521 ms |
51204 KB |
Output is correct |
66 |
Correct |
517 ms |
50764 KB |
Output is correct |
67 |
Correct |
567 ms |
50596 KB |
Output is correct |
68 |
Correct |
452 ms |
50072 KB |
Output is correct |
69 |
Correct |
494 ms |
50680 KB |
Output is correct |
70 |
Correct |
512 ms |
50736 KB |
Output is correct |
71 |
Correct |
501 ms |
50528 KB |
Output is correct |
72 |
Correct |
478 ms |
50420 KB |
Output is correct |
73 |
Correct |
577 ms |
50844 KB |
Output is correct |
74 |
Correct |
521 ms |
50844 KB |
Output is correct |
75 |
Correct |
542 ms |
50636 KB |
Output is correct |
76 |
Correct |
478 ms |
50888 KB |
Output is correct |
77 |
Correct |
445 ms |
45252 KB |
Output is correct |
78 |
Correct |
424 ms |
45224 KB |
Output is correct |
79 |
Correct |
393 ms |
44936 KB |
Output is correct |
80 |
Correct |
420 ms |
45092 KB |
Output is correct |
81 |
Correct |
385 ms |
45264 KB |
Output is correct |
82 |
Correct |
430 ms |
45444 KB |
Output is correct |
83 |
Correct |
408 ms |
44788 KB |
Output is correct |
84 |
Correct |
397 ms |
44868 KB |
Output is correct |
85 |
Correct |
372 ms |
44884 KB |
Output is correct |
86 |
Correct |
384 ms |
45336 KB |
Output is correct |
87 |
Correct |
385 ms |
45040 KB |
Output is correct |
88 |
Correct |
376 ms |
45572 KB |
Output is correct |
89 |
Correct |
411 ms |
46316 KB |
Output is correct |
90 |
Correct |
422 ms |
44700 KB |
Output is correct |
91 |
Correct |
351 ms |
44348 KB |
Output is correct |
92 |
Correct |
334 ms |
44264 KB |
Output is correct |
93 |
Correct |
371 ms |
44772 KB |
Output is correct |
94 |
Correct |
386 ms |
47064 KB |
Output is correct |
95 |
Correct |
350 ms |
44952 KB |
Output is correct |
96 |
Correct |
425 ms |
44740 KB |
Output is correct |
97 |
Correct |
415 ms |
44864 KB |
Output is correct |
98 |
Correct |
384 ms |
44260 KB |
Output is correct |
99 |
Correct |
392 ms |
44284 KB |
Output is correct |
100 |
Correct |
374 ms |
44816 KB |
Output is correct |
101 |
Correct |
368 ms |
44420 KB |
Output is correct |
102 |
Correct |
369 ms |
44972 KB |
Output is correct |