# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202854 | 2020-02-18T08:45:48 Z | Mercenary | Fire (JOI20_ho_t5) | C++14 | 390 ms | 59636 KB |
#include<bits/stdc++.h> #define taskname "A" #define pb push_back #define mp make_pair using namespace std; const int maxn = 2e5 + 6; typedef pair<int,int> ii; typedef long long ll; ll bit[maxn]; void U(int x , int val){ assert(x > 0); for( ; x < maxn ; x += x & -x)bit[x] += val; } ll Q(int x){ if(x <= 0)return 0; ll res = 0; for( ; x > 0 ; x &= x - 1)res += bit[x]; return res; } int n , q; int s[maxn] , pre[maxn] , suf[maxn]; vector<pair<ii,int>> query[maxn]; ll ans[maxn]; vector<ii> f[maxn] , g[maxn]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP","r",stdin); freopen(taskname".OUT","w",stdout); } cin >> n >> q; for(int i = 1 ; i <= n ; ++i){ cin >> s[i]; } for(int i = 1 ; i <= q ; ++i){ int t , l , r;cin >> t >> l >> r; query[t].pb(mp(mp(l,r),i)); } vector<int> val; for(int i = 1 ; i <= n ; ++i){ while(val.size() && s[val.back()] <= s[i])val.pop_back(); if(val.size())pre[i] = val.back(); else pre[i] = 0; val.pb(i); } val.clear(); for(int i = n ; i >= 1 ; --i){ while(val.size() && s[val.back()] < s[i])val.pop_back(); if(val.size())suf[i] = val.back(); else suf[i] = n + 1; val.pb(i); } for(int i = 1 ; i <= n ; ++i){ if(pre[i] == 0 || i - pre[i] > suf[i] - i){ for(int j = i ; j < suf[i] ; ++j){ f[j - i].pb(mp(j,s[i])); if(pre[i])f[j - pre[i]].pb(mp(j,-s[i])); } }else{ for(int j = pre[i] + 1 ; j <= i ; ++j){ g[i - j].pb(mp(j,s[i])); g[suf[i] - j].pb(mp(j,-s[i])); } } } for(int i = 0 ; i <= n ; ++i){ for(auto & c : f[i]){ U(c.first,c.second); } for(auto & c : query[i]){ ans[c.second] += Q(c.first.second) - Q(c.first.first-1); } } fill_n(bit,maxn,0); for(int i = 0 ; i <= n ; ++i){ for(auto & c : g[i]){ U(c.first,c.second); } for(auto & c : query[i]){ ans[c.second] += Q(c.first.second - i) - Q(c.first.first-i-1); } } for(int i = 1 ; i <= q ; ++i)cout << ans[i] << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 15992 KB | Output is correct |
2 | Correct | 14 ms | 15996 KB | Output is correct |
3 | Correct | 15 ms | 16120 KB | Output is correct |
4 | Correct | 14 ms | 15992 KB | Output is correct |
5 | Correct | 13 ms | 15992 KB | Output is correct |
6 | Correct | 13 ms | 15992 KB | Output is correct |
7 | Correct | 14 ms | 15992 KB | Output is correct |
8 | Correct | 13 ms | 16120 KB | Output is correct |
9 | Correct | 14 ms | 15992 KB | Output is correct |
10 | Correct | 14 ms | 15992 KB | Output is correct |
11 | Correct | 13 ms | 15992 KB | Output is correct |
12 | Correct | 14 ms | 16120 KB | Output is correct |
13 | Correct | 14 ms | 16120 KB | Output is correct |
14 | Correct | 14 ms | 15992 KB | Output is correct |
15 | Correct | 14 ms | 15992 KB | Output is correct |
16 | Correct | 15 ms | 15992 KB | Output is correct |
17 | Correct | 16 ms | 16120 KB | Output is correct |
18 | Correct | 14 ms | 16120 KB | Output is correct |
19 | Correct | 13 ms | 15992 KB | Output is correct |
20 | Correct | 15 ms | 15992 KB | Output is correct |
21 | Correct | 14 ms | 15992 KB | Output is correct |
22 | Correct | 14 ms | 15992 KB | Output is correct |
23 | Correct | 14 ms | 16120 KB | Output is correct |
24 | Correct | 14 ms | 15996 KB | Output is correct |
25 | Correct | 14 ms | 15992 KB | Output is correct |
26 | Correct | 14 ms | 15992 KB | Output is correct |
27 | Correct | 14 ms | 15992 KB | Output is correct |
28 | Correct | 13 ms | 15992 KB | Output is correct |
29 | Correct | 14 ms | 15996 KB | Output is correct |
30 | Correct | 14 ms | 15992 KB | Output is correct |
31 | Correct | 14 ms | 15992 KB | Output is correct |
32 | Correct | 14 ms | 16120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 15992 KB | Output is correct |
2 | Correct | 296 ms | 50976 KB | Output is correct |
3 | Correct | 301 ms | 54568 KB | Output is correct |
4 | Correct | 301 ms | 52352 KB | Output is correct |
5 | Correct | 296 ms | 55012 KB | Output is correct |
6 | Correct | 292 ms | 53012 KB | Output is correct |
7 | Correct | 290 ms | 51812 KB | Output is correct |
8 | Correct | 293 ms | 52816 KB | Output is correct |
9 | Correct | 298 ms | 53728 KB | Output is correct |
10 | Correct | 274 ms | 52196 KB | Output is correct |
11 | Correct | 291 ms | 53088 KB | Output is correct |
12 | Correct | 287 ms | 53964 KB | Output is correct |
13 | Correct | 275 ms | 51676 KB | Output is correct |
14 | Correct | 288 ms | 53944 KB | Output is correct |
15 | Correct | 298 ms | 53348 KB | Output is correct |
16 | Correct | 319 ms | 55904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 15992 KB | Output is correct |
2 | Correct | 375 ms | 57220 KB | Output is correct |
3 | Correct | 373 ms | 55520 KB | Output is correct |
4 | Correct | 390 ms | 59636 KB | Output is correct |
5 | Correct | 356 ms | 52184 KB | Output is correct |
6 | Correct | 351 ms | 52740 KB | Output is correct |
7 | Correct | 350 ms | 53036 KB | Output is correct |
8 | Correct | 347 ms | 53464 KB | Output is correct |
9 | Correct | 346 ms | 52696 KB | Output is correct |
10 | Correct | 363 ms | 54352 KB | Output is correct |
11 | Correct | 377 ms | 56804 KB | Output is correct |
12 | Correct | 361 ms | 55912 KB | Output is correct |
13 | Correct | 381 ms | 55940 KB | Output is correct |
14 | Correct | 340 ms | 50648 KB | Output is correct |
15 | Correct | 354 ms | 53976 KB | Output is correct |
16 | Correct | 355 ms | 54440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 217 ms | 29628 KB | Output is correct |
2 | Correct | 219 ms | 29668 KB | Output is correct |
3 | Correct | 220 ms | 30184 KB | Output is correct |
4 | Correct | 222 ms | 29672 KB | Output is correct |
5 | Correct | 209 ms | 30056 KB | Output is correct |
6 | Correct | 208 ms | 29544 KB | Output is correct |
7 | Correct | 213 ms | 29932 KB | Output is correct |
8 | Correct | 225 ms | 29988 KB | Output is correct |
9 | Correct | 211 ms | 29804 KB | Output is correct |
10 | Correct | 212 ms | 29548 KB | Output is correct |
11 | Correct | 225 ms | 30056 KB | Output is correct |
12 | Correct | 219 ms | 29544 KB | Output is correct |
13 | Correct | 224 ms | 30056 KB | Output is correct |
14 | Correct | 222 ms | 30028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 15992 KB | Output is correct |
2 | Correct | 14 ms | 15996 KB | Output is correct |
3 | Correct | 15 ms | 16120 KB | Output is correct |
4 | Correct | 14 ms | 15992 KB | Output is correct |
5 | Correct | 13 ms | 15992 KB | Output is correct |
6 | Correct | 13 ms | 15992 KB | Output is correct |
7 | Correct | 14 ms | 15992 KB | Output is correct |
8 | Correct | 13 ms | 16120 KB | Output is correct |
9 | Correct | 14 ms | 15992 KB | Output is correct |
10 | Correct | 14 ms | 15992 KB | Output is correct |
11 | Correct | 13 ms | 15992 KB | Output is correct |
12 | Correct | 14 ms | 16120 KB | Output is correct |
13 | Correct | 14 ms | 16120 KB | Output is correct |
14 | Correct | 14 ms | 15992 KB | Output is correct |
15 | Correct | 14 ms | 15992 KB | Output is correct |
16 | Correct | 15 ms | 15992 KB | Output is correct |
17 | Correct | 16 ms | 16120 KB | Output is correct |
18 | Correct | 14 ms | 16120 KB | Output is correct |
19 | Correct | 13 ms | 15992 KB | Output is correct |
20 | Correct | 15 ms | 15992 KB | Output is correct |
21 | Correct | 14 ms | 15992 KB | Output is correct |
22 | Correct | 14 ms | 15992 KB | Output is correct |
23 | Correct | 14 ms | 16120 KB | Output is correct |
24 | Correct | 14 ms | 15996 KB | Output is correct |
25 | Correct | 14 ms | 15992 KB | Output is correct |
26 | Correct | 14 ms | 15992 KB | Output is correct |
27 | Correct | 14 ms | 15992 KB | Output is correct |
28 | Correct | 13 ms | 15992 KB | Output is correct |
29 | Correct | 14 ms | 15996 KB | Output is correct |
30 | Correct | 14 ms | 15992 KB | Output is correct |
31 | Correct | 14 ms | 15992 KB | Output is correct |
32 | Correct | 14 ms | 16120 KB | Output is correct |
33 | Correct | 369 ms | 53548 KB | Output is correct |
34 | Correct | 384 ms | 57048 KB | Output is correct |
35 | Correct | 389 ms | 55004 KB | Output is correct |
36 | Correct | 372 ms | 54104 KB | Output is correct |
37 | Correct | 351 ms | 54720 KB | Output is correct |
38 | Correct | 366 ms | 55768 KB | Output is correct |
39 | Correct | 369 ms | 54224 KB | Output is correct |
40 | Correct | 360 ms | 52056 KB | Output is correct |
41 | Correct | 355 ms | 54248 KB | Output is correct |
42 | Correct | 382 ms | 59608 KB | Output is correct |
43 | Correct | 314 ms | 54104 KB | Output is correct |
44 | Correct | 299 ms | 50524 KB | Output is correct |
45 | Correct | 291 ms | 50008 KB | Output is correct |
46 | Correct | 313 ms | 53464 KB | Output is correct |
47 | Correct | 312 ms | 54460 KB | Output is correct |
48 | Correct | 307 ms | 56528 KB | Output is correct |
49 | Correct | 310 ms | 56024 KB | Output is correct |
50 | Correct | 313 ms | 53208 KB | Output is correct |
51 | Correct | 312 ms | 54492 KB | Output is correct |
52 | Correct | 321 ms | 57364 KB | Output is correct |
53 | Correct | 307 ms | 54880 KB | Output is correct |
54 | Correct | 318 ms | 53240 KB | Output is correct |
55 | Correct | 326 ms | 54948 KB | Output is correct |
56 | Correct | 362 ms | 55256 KB | Output is correct |
57 | Correct | 308 ms | 51920 KB | Output is correct |
58 | Correct | 320 ms | 51928 KB | Output is correct |
59 | Correct | 296 ms | 50976 KB | Output is correct |
60 | Correct | 301 ms | 54568 KB | Output is correct |
61 | Correct | 301 ms | 52352 KB | Output is correct |
62 | Correct | 296 ms | 55012 KB | Output is correct |
63 | Correct | 292 ms | 53012 KB | Output is correct |
64 | Correct | 290 ms | 51812 KB | Output is correct |
65 | Correct | 293 ms | 52816 KB | Output is correct |
66 | Correct | 298 ms | 53728 KB | Output is correct |
67 | Correct | 274 ms | 52196 KB | Output is correct |
68 | Correct | 291 ms | 53088 KB | Output is correct |
69 | Correct | 287 ms | 53964 KB | Output is correct |
70 | Correct | 275 ms | 51676 KB | Output is correct |
71 | Correct | 288 ms | 53944 KB | Output is correct |
72 | Correct | 298 ms | 53348 KB | Output is correct |
73 | Correct | 319 ms | 55904 KB | Output is correct |
74 | Correct | 375 ms | 57220 KB | Output is correct |
75 | Correct | 373 ms | 55520 KB | Output is correct |
76 | Correct | 390 ms | 59636 KB | Output is correct |
77 | Correct | 356 ms | 52184 KB | Output is correct |
78 | Correct | 351 ms | 52740 KB | Output is correct |
79 | Correct | 350 ms | 53036 KB | Output is correct |
80 | Correct | 347 ms | 53464 KB | Output is correct |
81 | Correct | 346 ms | 52696 KB | Output is correct |
82 | Correct | 363 ms | 54352 KB | Output is correct |
83 | Correct | 377 ms | 56804 KB | Output is correct |
84 | Correct | 361 ms | 55912 KB | Output is correct |
85 | Correct | 381 ms | 55940 KB | Output is correct |
86 | Correct | 340 ms | 50648 KB | Output is correct |
87 | Correct | 354 ms | 53976 KB | Output is correct |
88 | Correct | 355 ms | 54440 KB | Output is correct |
89 | Correct | 217 ms | 29628 KB | Output is correct |
90 | Correct | 219 ms | 29668 KB | Output is correct |
91 | Correct | 220 ms | 30184 KB | Output is correct |
92 | Correct | 222 ms | 29672 KB | Output is correct |
93 | Correct | 209 ms | 30056 KB | Output is correct |
94 | Correct | 208 ms | 29544 KB | Output is correct |
95 | Correct | 213 ms | 29932 KB | Output is correct |
96 | Correct | 225 ms | 29988 KB | Output is correct |
97 | Correct | 211 ms | 29804 KB | Output is correct |
98 | Correct | 212 ms | 29548 KB | Output is correct |
99 | Correct | 225 ms | 30056 KB | Output is correct |
100 | Correct | 219 ms | 29544 KB | Output is correct |
101 | Correct | 224 ms | 30056 KB | Output is correct |
102 | Correct | 222 ms | 30028 KB | Output is correct |