#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 1000000
lli n,q,apu,a;
lli w[MAX+2],l[MAX+2],r[MAX+2],k[MAX+2],res[MAX+2];
lli finales[MAX+2];
stack<lli> monotone;
lli dsu[MAX+2],M[MAX+2];
lli sube(lli a) {
if (dsu[a] == a) return a;
lli x = sube(dsu[a]);
M[a] = max(M[dsu[a]], M[a]);
dsu[a] = x;
return dsu[a];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
rep(i,1,n) cin >> w[i];
rep(i,1,q) cin >> l[i] >> r[i] >> k[i];
iota(finales+1, finales+q+1, 1);
sort(finales+1, finales+q+1, [&] (lli a, lli b) {
return r[a] < r[b];
});
iota(dsu+1,dsu+n+1,1);
apu = 1;
rep(i,1,n) {
while (!monotone.empty() && w[monotone.top()] <= w[i]) {
dsu[monotone.top()] = i;
monotone.pop();
}
if (!monotone.empty()) M[monotone.top()] = w[monotone.top()] + w[i];
monotone.push(i);
while (apu <= q && r[finales[apu] ] == i) {
a = sube( l[finales[apu]] );
a = M[l[finales[apu]]];
if (a <= k[finales[apu]]) res[finales[apu]] = 1;
apu++;
}
}
rep(i,1,q) cout << res[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
699 ms |
29676 KB |
Output is correct |
2 |
Correct |
671 ms |
29828 KB |
Output is correct |
3 |
Correct |
688 ms |
29872 KB |
Output is correct |
4 |
Correct |
680 ms |
29764 KB |
Output is correct |
5 |
Correct |
829 ms |
33536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
3660 KB |
Output is correct |
2 |
Correct |
51 ms |
3596 KB |
Output is correct |
3 |
Correct |
50 ms |
4544 KB |
Output is correct |
4 |
Correct |
53 ms |
3920 KB |
Output is correct |
5 |
Correct |
56 ms |
3636 KB |
Output is correct |
6 |
Correct |
44 ms |
5964 KB |
Output is correct |
7 |
Correct |
48 ms |
5980 KB |
Output is correct |
8 |
Correct |
55 ms |
3588 KB |
Output is correct |
9 |
Correct |
43 ms |
2508 KB |
Output is correct |
10 |
Correct |
43 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
120 ms |
6948 KB |
Output is correct |
20 |
Correct |
128 ms |
7008 KB |
Output is correct |
21 |
Correct |
117 ms |
9476 KB |
Output is correct |
22 |
Correct |
119 ms |
13412 KB |
Output is correct |
23 |
Correct |
113 ms |
13380 KB |
Output is correct |
24 |
Correct |
119 ms |
19272 KB |
Output is correct |
25 |
Correct |
122 ms |
19276 KB |
Output is correct |
26 |
Correct |
130 ms |
17572 KB |
Output is correct |
27 |
Correct |
129 ms |
17572 KB |
Output is correct |
28 |
Correct |
125 ms |
16684 KB |
Output is correct |
29 |
Correct |
142 ms |
13644 KB |
Output is correct |
30 |
Correct |
131 ms |
13556 KB |
Output is correct |
31 |
Correct |
127 ms |
13856 KB |
Output is correct |
32 |
Correct |
127 ms |
13940 KB |
Output is correct |
33 |
Correct |
134 ms |
13900 KB |
Output is correct |
34 |
Correct |
121 ms |
19424 KB |
Output is correct |
35 |
Correct |
115 ms |
19444 KB |
Output is correct |
36 |
Correct |
110 ms |
19264 KB |
Output is correct |
37 |
Correct |
112 ms |
19236 KB |
Output is correct |
38 |
Correct |
110 ms |
19428 KB |
Output is correct |
39 |
Correct |
119 ms |
12080 KB |
Output is correct |
40 |
Correct |
117 ms |
10704 KB |
Output is correct |
41 |
Correct |
103 ms |
11852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
699 ms |
29676 KB |
Output is correct |
20 |
Correct |
671 ms |
29828 KB |
Output is correct |
21 |
Correct |
688 ms |
29872 KB |
Output is correct |
22 |
Correct |
680 ms |
29764 KB |
Output is correct |
23 |
Correct |
829 ms |
33536 KB |
Output is correct |
24 |
Correct |
63 ms |
3660 KB |
Output is correct |
25 |
Correct |
51 ms |
3596 KB |
Output is correct |
26 |
Correct |
50 ms |
4544 KB |
Output is correct |
27 |
Correct |
53 ms |
3920 KB |
Output is correct |
28 |
Correct |
56 ms |
3636 KB |
Output is correct |
29 |
Correct |
44 ms |
5964 KB |
Output is correct |
30 |
Correct |
48 ms |
5980 KB |
Output is correct |
31 |
Correct |
55 ms |
3588 KB |
Output is correct |
32 |
Correct |
43 ms |
2508 KB |
Output is correct |
33 |
Correct |
43 ms |
3660 KB |
Output is correct |
34 |
Correct |
120 ms |
6948 KB |
Output is correct |
35 |
Correct |
128 ms |
7008 KB |
Output is correct |
36 |
Correct |
117 ms |
9476 KB |
Output is correct |
37 |
Correct |
119 ms |
13412 KB |
Output is correct |
38 |
Correct |
113 ms |
13380 KB |
Output is correct |
39 |
Correct |
119 ms |
19272 KB |
Output is correct |
40 |
Correct |
122 ms |
19276 KB |
Output is correct |
41 |
Correct |
130 ms |
17572 KB |
Output is correct |
42 |
Correct |
129 ms |
17572 KB |
Output is correct |
43 |
Correct |
125 ms |
16684 KB |
Output is correct |
44 |
Correct |
142 ms |
13644 KB |
Output is correct |
45 |
Correct |
131 ms |
13556 KB |
Output is correct |
46 |
Correct |
127 ms |
13856 KB |
Output is correct |
47 |
Correct |
127 ms |
13940 KB |
Output is correct |
48 |
Correct |
134 ms |
13900 KB |
Output is correct |
49 |
Correct |
121 ms |
19424 KB |
Output is correct |
50 |
Correct |
115 ms |
19444 KB |
Output is correct |
51 |
Correct |
110 ms |
19264 KB |
Output is correct |
52 |
Correct |
112 ms |
19236 KB |
Output is correct |
53 |
Correct |
110 ms |
19428 KB |
Output is correct |
54 |
Correct |
119 ms |
12080 KB |
Output is correct |
55 |
Correct |
117 ms |
10704 KB |
Output is correct |
56 |
Correct |
103 ms |
11852 KB |
Output is correct |
57 |
Correct |
769 ms |
67080 KB |
Output is correct |
58 |
Correct |
719 ms |
67132 KB |
Output is correct |
59 |
Correct |
679 ms |
66976 KB |
Output is correct |
60 |
Correct |
672 ms |
67120 KB |
Output is correct |
61 |
Correct |
648 ms |
66988 KB |
Output is correct |
62 |
Correct |
679 ms |
67156 KB |
Output is correct |
63 |
Correct |
650 ms |
96116 KB |
Output is correct |
64 |
Correct |
641 ms |
96100 KB |
Output is correct |
65 |
Correct |
896 ms |
83584 KB |
Output is correct |
66 |
Correct |
810 ms |
83608 KB |
Output is correct |
67 |
Correct |
823 ms |
82688 KB |
Output is correct |
68 |
Correct |
822 ms |
67168 KB |
Output is correct |
69 |
Correct |
826 ms |
67220 KB |
Output is correct |
70 |
Correct |
870 ms |
70276 KB |
Output is correct |
71 |
Correct |
842 ms |
70208 KB |
Output is correct |
72 |
Correct |
902 ms |
70224 KB |
Output is correct |
73 |
Correct |
657 ms |
94892 KB |
Output is correct |
74 |
Correct |
634 ms |
96008 KB |
Output is correct |
75 |
Correct |
645 ms |
94892 KB |
Output is correct |
76 |
Correct |
634 ms |
94904 KB |
Output is correct |
77 |
Correct |
592 ms |
94872 KB |
Output is correct |
78 |
Correct |
706 ms |
60968 KB |
Output is correct |
79 |
Correct |
502 ms |
50664 KB |
Output is correct |
80 |
Correct |
641 ms |
58320 KB |
Output is correct |