#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define Base 311
#define endl '\n'
#define fi first
#define fii(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define fill(a,n) memset(a, n, sizeof(a));
#define getbit(i, j) ((i >> j) & 1)
#define minimize(x, y) x = (x > y ? y : x)
#define maximize(x, y) x = (x < y ? y : x)
#define ins insert
#define int long long
#define ll long long
#define maxn 1000006
#define MOD 1000000007
#define name "file"
#define pb push_back
#define pii pair< int, int >
#define pll pair< long long , long long >
#define re return
#define sz(x) int(x.size())
#define se second
#define ull unsigned long long
void ctime () {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock () / CLOCKS_PER_SEC << "ms\n" ;
}
void iof () {
if ( fopen ( name ".inp" , "r" ))
{
freopen ( name ".inp" , "r" , stdin );
freopen ( name ".out" , "w", stdout );
}
ios_base :: sync_with_stdio ( 0 );
cin . tie ( NULL ), cout . tie ( NULL );
}
struct ddata {
ll pos, id, k;
};
vector<ddata> ques[maxn];
ll T[4 * maxn];
ll a[maxn];
ll ans[maxn];
void update(int id, int l, int r, int pos, ll val)
{
if (l > pos || r < pos) re;
if (l == r)
{
T[id] = val;
re;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, pos, val);
update(id * 2 + 1, mid + 1, r, pos, val);
T[id] = max(T[id * 2], T[id * 2 + 1]);
}
ll get(int id, int l, int r, int u, int v)
{
if (u > r || l > v) re 0;
if (l >= u && r <= v) re T[id];
int mid = (l + r) / 2;
re max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
signed main(){
iof();
int n, m;
cin >> n >> m;
fii(i, 1, n)
cin >> a[i];
fii(i, 1, m)
{
ll l, r, val;
cin >> l >> r >> val;
ques[r].pb({l, i, val});
}
stack<ll> st;
fii(i, 1, n)
{
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if (st.size()) update(1, 1, n, st.top(), a[st.top()] + a[i]);
st.push(i);
for(auto x : ques[i])
{
int l = x.pos, id = x.id, k = x.k;
if (get(1, 1, n, l, i) <= k) ans[id] = 1;
else ans[id] = 0;
}
}
fii(i, 1, m) cout << ans[i] << endl;
ctime();
re 0;
}
Compilation message
sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen ( name ".inp" , "r" , stdin );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen ( name ".out" , "w", stdout );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29528 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
4 ms |
29532 KB |
Output is correct |
4 |
Correct |
4 ms |
29532 KB |
Output is correct |
5 |
Correct |
4 ms |
29780 KB |
Output is correct |
6 |
Correct |
4 ms |
29528 KB |
Output is correct |
7 |
Correct |
4 ms |
29664 KB |
Output is correct |
8 |
Correct |
3 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
4 ms |
27484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29528 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
4 ms |
29532 KB |
Output is correct |
4 |
Correct |
4 ms |
29532 KB |
Output is correct |
5 |
Correct |
4 ms |
29780 KB |
Output is correct |
6 |
Correct |
4 ms |
29528 KB |
Output is correct |
7 |
Correct |
4 ms |
29664 KB |
Output is correct |
8 |
Correct |
3 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
4 ms |
27484 KB |
Output is correct |
11 |
Correct |
5 ms |
29788 KB |
Output is correct |
12 |
Correct |
5 ms |
29788 KB |
Output is correct |
13 |
Correct |
6 ms |
29788 KB |
Output is correct |
14 |
Correct |
8 ms |
29788 KB |
Output is correct |
15 |
Correct |
7 ms |
29788 KB |
Output is correct |
16 |
Correct |
5 ms |
27920 KB |
Output is correct |
17 |
Correct |
6 ms |
27740 KB |
Output is correct |
18 |
Correct |
5 ms |
27740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
810 ms |
91988 KB |
Output is correct |
2 |
Correct |
790 ms |
93008 KB |
Output is correct |
3 |
Correct |
812 ms |
91984 KB |
Output is correct |
4 |
Correct |
871 ms |
92076 KB |
Output is correct |
5 |
Correct |
703 ms |
76624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
39268 KB |
Output is correct |
2 |
Correct |
54 ms |
39508 KB |
Output is correct |
3 |
Correct |
62 ms |
35312 KB |
Output is correct |
4 |
Correct |
56 ms |
35260 KB |
Output is correct |
5 |
Correct |
55 ms |
35336 KB |
Output is correct |
6 |
Correct |
44 ms |
37460 KB |
Output is correct |
7 |
Correct |
67 ms |
37460 KB |
Output is correct |
8 |
Correct |
55 ms |
34936 KB |
Output is correct |
9 |
Correct |
25 ms |
32784 KB |
Output is correct |
10 |
Correct |
50 ms |
35016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29528 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
4 ms |
29532 KB |
Output is correct |
4 |
Correct |
4 ms |
29532 KB |
Output is correct |
5 |
Correct |
4 ms |
29780 KB |
Output is correct |
6 |
Correct |
4 ms |
29528 KB |
Output is correct |
7 |
Correct |
4 ms |
29664 KB |
Output is correct |
8 |
Correct |
3 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
4 ms |
27484 KB |
Output is correct |
11 |
Correct |
5 ms |
29788 KB |
Output is correct |
12 |
Correct |
5 ms |
29788 KB |
Output is correct |
13 |
Correct |
6 ms |
29788 KB |
Output is correct |
14 |
Correct |
8 ms |
29788 KB |
Output is correct |
15 |
Correct |
7 ms |
29788 KB |
Output is correct |
16 |
Correct |
5 ms |
27920 KB |
Output is correct |
17 |
Correct |
6 ms |
27740 KB |
Output is correct |
18 |
Correct |
5 ms |
27740 KB |
Output is correct |
19 |
Correct |
193 ms |
44024 KB |
Output is correct |
20 |
Correct |
138 ms |
43860 KB |
Output is correct |
21 |
Correct |
145 ms |
45396 KB |
Output is correct |
22 |
Correct |
117 ms |
45396 KB |
Output is correct |
23 |
Correct |
118 ms |
45516 KB |
Output is correct |
24 |
Correct |
93 ms |
39396 KB |
Output is correct |
25 |
Correct |
100 ms |
39512 KB |
Output is correct |
26 |
Correct |
112 ms |
39148 KB |
Output is correct |
27 |
Correct |
114 ms |
38972 KB |
Output is correct |
28 |
Correct |
119 ms |
38832 KB |
Output is correct |
29 |
Correct |
122 ms |
38740 KB |
Output is correct |
30 |
Correct |
125 ms |
38688 KB |
Output is correct |
31 |
Correct |
122 ms |
38740 KB |
Output is correct |
32 |
Correct |
140 ms |
38720 KB |
Output is correct |
33 |
Correct |
120 ms |
38648 KB |
Output is correct |
34 |
Correct |
109 ms |
43000 KB |
Output is correct |
35 |
Correct |
121 ms |
42836 KB |
Output is correct |
36 |
Correct |
87 ms |
43084 KB |
Output is correct |
37 |
Correct |
84 ms |
42968 KB |
Output is correct |
38 |
Correct |
85 ms |
42900 KB |
Output is correct |
39 |
Correct |
101 ms |
41224 KB |
Output is correct |
40 |
Correct |
75 ms |
37884 KB |
Output is correct |
41 |
Correct |
92 ms |
39680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29528 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
4 ms |
29532 KB |
Output is correct |
4 |
Correct |
4 ms |
29532 KB |
Output is correct |
5 |
Correct |
4 ms |
29780 KB |
Output is correct |
6 |
Correct |
4 ms |
29528 KB |
Output is correct |
7 |
Correct |
4 ms |
29664 KB |
Output is correct |
8 |
Correct |
3 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
4 ms |
27484 KB |
Output is correct |
11 |
Correct |
5 ms |
29788 KB |
Output is correct |
12 |
Correct |
5 ms |
29788 KB |
Output is correct |
13 |
Correct |
6 ms |
29788 KB |
Output is correct |
14 |
Correct |
8 ms |
29788 KB |
Output is correct |
15 |
Correct |
7 ms |
29788 KB |
Output is correct |
16 |
Correct |
5 ms |
27920 KB |
Output is correct |
17 |
Correct |
6 ms |
27740 KB |
Output is correct |
18 |
Correct |
5 ms |
27740 KB |
Output is correct |
19 |
Correct |
810 ms |
91988 KB |
Output is correct |
20 |
Correct |
790 ms |
93008 KB |
Output is correct |
21 |
Correct |
812 ms |
91984 KB |
Output is correct |
22 |
Correct |
871 ms |
92076 KB |
Output is correct |
23 |
Correct |
703 ms |
76624 KB |
Output is correct |
24 |
Correct |
71 ms |
39268 KB |
Output is correct |
25 |
Correct |
54 ms |
39508 KB |
Output is correct |
26 |
Correct |
62 ms |
35312 KB |
Output is correct |
27 |
Correct |
56 ms |
35260 KB |
Output is correct |
28 |
Correct |
55 ms |
35336 KB |
Output is correct |
29 |
Correct |
44 ms |
37460 KB |
Output is correct |
30 |
Correct |
67 ms |
37460 KB |
Output is correct |
31 |
Correct |
55 ms |
34936 KB |
Output is correct |
32 |
Correct |
25 ms |
32784 KB |
Output is correct |
33 |
Correct |
50 ms |
35016 KB |
Output is correct |
34 |
Correct |
193 ms |
44024 KB |
Output is correct |
35 |
Correct |
138 ms |
43860 KB |
Output is correct |
36 |
Correct |
145 ms |
45396 KB |
Output is correct |
37 |
Correct |
117 ms |
45396 KB |
Output is correct |
38 |
Correct |
118 ms |
45516 KB |
Output is correct |
39 |
Correct |
93 ms |
39396 KB |
Output is correct |
40 |
Correct |
100 ms |
39512 KB |
Output is correct |
41 |
Correct |
112 ms |
39148 KB |
Output is correct |
42 |
Correct |
114 ms |
38972 KB |
Output is correct |
43 |
Correct |
119 ms |
38832 KB |
Output is correct |
44 |
Correct |
122 ms |
38740 KB |
Output is correct |
45 |
Correct |
125 ms |
38688 KB |
Output is correct |
46 |
Correct |
122 ms |
38740 KB |
Output is correct |
47 |
Correct |
140 ms |
38720 KB |
Output is correct |
48 |
Correct |
120 ms |
38648 KB |
Output is correct |
49 |
Correct |
109 ms |
43000 KB |
Output is correct |
50 |
Correct |
121 ms |
42836 KB |
Output is correct |
51 |
Correct |
87 ms |
43084 KB |
Output is correct |
52 |
Correct |
84 ms |
42968 KB |
Output is correct |
53 |
Correct |
85 ms |
42900 KB |
Output is correct |
54 |
Correct |
101 ms |
41224 KB |
Output is correct |
55 |
Correct |
75 ms |
37884 KB |
Output is correct |
56 |
Correct |
92 ms |
39680 KB |
Output is correct |
57 |
Correct |
836 ms |
92244 KB |
Output is correct |
58 |
Correct |
788 ms |
92160 KB |
Output is correct |
59 |
Correct |
732 ms |
92924 KB |
Output is correct |
60 |
Correct |
720 ms |
94032 KB |
Output is correct |
61 |
Correct |
744 ms |
93272 KB |
Output is correct |
62 |
Correct |
727 ms |
93092 KB |
Output is correct |
63 |
Correct |
458 ms |
79476 KB |
Output is correct |
64 |
Correct |
449 ms |
79440 KB |
Output is correct |
65 |
Correct |
580 ms |
77648 KB |
Output is correct |
66 |
Correct |
605 ms |
77648 KB |
Output is correct |
67 |
Correct |
591 ms |
77636 KB |
Output is correct |
68 |
Correct |
632 ms |
76900 KB |
Output is correct |
69 |
Correct |
630 ms |
76916 KB |
Output is correct |
70 |
Correct |
639 ms |
76884 KB |
Output is correct |
71 |
Correct |
617 ms |
76880 KB |
Output is correct |
72 |
Correct |
641 ms |
76836 KB |
Output is correct |
73 |
Correct |
418 ms |
80880 KB |
Output is correct |
74 |
Correct |
438 ms |
81148 KB |
Output is correct |
75 |
Correct |
421 ms |
81256 KB |
Output is correct |
76 |
Correct |
416 ms |
81408 KB |
Output is correct |
77 |
Correct |
436 ms |
80788 KB |
Output is correct |
78 |
Correct |
563 ms |
81268 KB |
Output is correct |
79 |
Correct |
420 ms |
68328 KB |
Output is correct |
80 |
Correct |
550 ms |
74220 KB |
Output is correct |