# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
367227 |
2021-02-16T16:17:01 Z |
piddddgy |
Fire (JOI20_ho_t5) |
C++11 |
|
1000 ms |
24428 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ld long double
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
const int maxn = 200500;
int n, q;
int a[maxn];
int seg[4*maxn];
void upd( int pos, int val, int ind, int cl, int cr) {
if(cl > cr) return;
if(cl == cr) {
// cerr << "setting " << ind << " to " << val << endl;
seg[ind] = val;
} else {
int cm = (cl+cr)/2;
if(pos <= cm) {
upd(pos, val, 2*ind, cl, cm);
} else {
upd(pos, val, 2*ind+1, cm+1, cr);
}
seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}
}
int query(int l, int r, int ind, int cl, int cr) {
if(cl > cr) return -1e18;
if(l > r) return -1e18;
if(cl == l and cr == r) {
return seg[ind];
}
int cm = (cl+cr)/2;
return max(query(l, min(cm, r), 2*ind, cl, cm),
query(max(l, cm+1), r, 2*ind+1, cm+1, cr));
}
int t[maxn], l[maxn], r[maxn];
int psa[maxn];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
upd(i, a[i], 1, 1, n);
}
set<int> S;
for(int i = 1; i <= q; i++) {
cin >> t[i] >> l[i] >> r[i];
S.emplace(t[i]);
}
if(sz(S) == 1) {
int k = *S.begin();
for(int i = 1; i <= n; i++) {
psa[i] = query(max(1LL, i-k), i, 1, 1, n);
psa[i] += psa[i-1];
}
for(int i = 1; i <= q; i++) {
cout << psa[r[i]]-psa[l[i]-1] << endl;
}
} else {
for(int i = 1; i <= q; i++) {
watch(t[i])
int ans = 0;
for(int j = l[i]; j <= r[i]; j++) {
int val = query(max(1LL, j-t[i]), j, 1, 1, n);
cerr << j << " is " << val << endl;
cerr << "quried " << max(1LL, j-t[i]) << "," << j << endl;
ans += val;
}
cout << ans << endl;
}
}
}
/*
Did you read the bounds?
Did you make typos?
Are there edge cases (N=1?)
Are segay sizes proper?
Integer overflow?
DS reset properly between test cases?
Is using long longs causing TLE?
Are you using floating points?
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
248 ms |
20716 KB |
Output is correct |
3 |
Correct |
193 ms |
20764 KB |
Output is correct |
4 |
Correct |
220 ms |
20716 KB |
Output is correct |
5 |
Correct |
209 ms |
20716 KB |
Output is correct |
6 |
Correct |
215 ms |
20412 KB |
Output is correct |
7 |
Correct |
267 ms |
20844 KB |
Output is correct |
8 |
Correct |
224 ms |
20868 KB |
Output is correct |
9 |
Correct |
206 ms |
20844 KB |
Output is correct |
10 |
Correct |
200 ms |
20716 KB |
Output is correct |
11 |
Correct |
200 ms |
21100 KB |
Output is correct |
12 |
Correct |
192 ms |
20516 KB |
Output is correct |
13 |
Correct |
220 ms |
20460 KB |
Output is correct |
14 |
Correct |
205 ms |
20460 KB |
Output is correct |
15 |
Correct |
216 ms |
20460 KB |
Output is correct |
16 |
Correct |
218 ms |
20516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
368 ms |
24428 KB |
Output is correct |
3 |
Correct |
311 ms |
23916 KB |
Output is correct |
4 |
Correct |
343 ms |
24300 KB |
Output is correct |
5 |
Correct |
326 ms |
23788 KB |
Output is correct |
6 |
Correct |
316 ms |
23916 KB |
Output is correct |
7 |
Correct |
362 ms |
23916 KB |
Output is correct |
8 |
Correct |
327 ms |
24172 KB |
Output is correct |
9 |
Correct |
332 ms |
24044 KB |
Output is correct |
10 |
Correct |
301 ms |
23660 KB |
Output is correct |
11 |
Correct |
344 ms |
24172 KB |
Output is correct |
12 |
Correct |
311 ms |
23916 KB |
Output is correct |
13 |
Correct |
413 ms |
24264 KB |
Output is correct |
14 |
Correct |
328 ms |
23788 KB |
Output is correct |
15 |
Correct |
321 ms |
24048 KB |
Output is correct |
16 |
Correct |
352 ms |
23628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
20332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
248 ms |
20716 KB |
Output is correct |
34 |
Correct |
193 ms |
20764 KB |
Output is correct |
35 |
Correct |
220 ms |
20716 KB |
Output is correct |
36 |
Correct |
209 ms |
20716 KB |
Output is correct |
37 |
Correct |
215 ms |
20412 KB |
Output is correct |
38 |
Correct |
267 ms |
20844 KB |
Output is correct |
39 |
Correct |
224 ms |
20868 KB |
Output is correct |
40 |
Correct |
206 ms |
20844 KB |
Output is correct |
41 |
Correct |
200 ms |
20716 KB |
Output is correct |
42 |
Correct |
200 ms |
21100 KB |
Output is correct |
43 |
Correct |
192 ms |
20516 KB |
Output is correct |
44 |
Correct |
220 ms |
20460 KB |
Output is correct |
45 |
Correct |
205 ms |
20460 KB |
Output is correct |
46 |
Correct |
216 ms |
20460 KB |
Output is correct |
47 |
Correct |
218 ms |
20516 KB |
Output is correct |
48 |
Correct |
368 ms |
24428 KB |
Output is correct |
49 |
Correct |
311 ms |
23916 KB |
Output is correct |
50 |
Correct |
343 ms |
24300 KB |
Output is correct |
51 |
Correct |
326 ms |
23788 KB |
Output is correct |
52 |
Correct |
316 ms |
23916 KB |
Output is correct |
53 |
Correct |
362 ms |
23916 KB |
Output is correct |
54 |
Correct |
327 ms |
24172 KB |
Output is correct |
55 |
Correct |
332 ms |
24044 KB |
Output is correct |
56 |
Correct |
301 ms |
23660 KB |
Output is correct |
57 |
Correct |
344 ms |
24172 KB |
Output is correct |
58 |
Correct |
311 ms |
23916 KB |
Output is correct |
59 |
Correct |
413 ms |
24264 KB |
Output is correct |
60 |
Correct |
328 ms |
23788 KB |
Output is correct |
61 |
Correct |
321 ms |
24048 KB |
Output is correct |
62 |
Correct |
352 ms |
23628 KB |
Output is correct |
63 |
Execution timed out |
1089 ms |
20332 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |