#include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define fo(i, a, b) for (int i = a; i >= b; i--)
#define minimize(a, b) a = (a < b ? a : b)
#define maximize(a, b) a = (a > b ? a : b)
#define fi first
#define se second
#define ll long long
#define pii pair <int, int>
#define pb push_back
#define pi acos(-1)
#define sz(a) (int)a.size()
#define getbit(a, b) (((a) >> (b)) & 1)
#define INOUT "main"
#define INFT 0x3f3f3f3f
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cout << *it << " = [" << a << "]" << '\n';
err(++it, args...);
}
#define debug1(a, st, en) { cout << #a << " = ["; int kt = false; f(i, st, en) {if (kt) cout << ", "; kt = true; cout << a[i];} cout << "]\n"; }
void ctime()
{
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
void file()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(INOUT".INP", "r"))
{
freopen(INOUT".INP", "r", stdin);
freopen(INOUT".OUT", "w", stdout);
}
}
struct NEW
{
int st, id, mood;
};
const int MX_N = 1e6 + 5;
int n, m;
int a[MX_N], t[MX_N * 4], res[MX_N];
vector <NEW> v[MX_N];
void UPDATE(int id, int l, int r, int pos, int val)
{
if (l == r)
{
t[id] = val;
return;
}
int mid = (l + r) / 2;
if (pos <= mid) UPDATE(id * 2, l, mid, pos, val);
else UPDATE(id * 2 + 1, mid + 1, r, pos, val);
t[id] = max(t[id * 2], t[id * 2 + 1]);
}
int GET(int id, int l, int r, int u, int v)
{
if (r < u || l > v) return 0;
if (l >= u && r <= v) return t[id];
int mid = (l + r) / 2;
return max(GET(id * 2, l, mid, u, v), GET(id * 2 + 1, mid + 1, r, u, v));
}
int main()
{
file();
cin >> n >> m;
f(i, 1, n) cin >> a[i];
f(i, 1, m)
{
int l, r, k;
cin >> l >> r >> k;
v[r].pb({l, i, k});
}
stack <int> s;
f(i, 1, n)
{
while(!s.empty() && a[s.top()] <= a[i]) s.pop();
if (s.size()) UPDATE(1, 1, n, s.top(), a[s.top()] + a[i]);
s.push(i);
for (auto x : v[i])
{
if (GET(1, 1, n, x.st, i) <= x.mood) res[x.id] = 1;
else res[x.id] = 0;
}
}
f(i, 1, m) cout << res[i] << '\n';
ctime();
return 0;
}
Compilation message
sortbooks.cpp: In function 'void file()':
sortbooks.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | freopen(INOUT".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen(INOUT".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
4 ms |
27228 KB |
Output is correct |
3 |
Correct |
5 ms |
29272 KB |
Output is correct |
4 |
Correct |
4 ms |
29276 KB |
Output is correct |
5 |
Correct |
4 ms |
29276 KB |
Output is correct |
6 |
Correct |
4 ms |
29276 KB |
Output is correct |
7 |
Correct |
4 ms |
29296 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27228 KB |
Output is correct |
10 |
Correct |
4 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
4 ms |
27228 KB |
Output is correct |
3 |
Correct |
5 ms |
29272 KB |
Output is correct |
4 |
Correct |
4 ms |
29276 KB |
Output is correct |
5 |
Correct |
4 ms |
29276 KB |
Output is correct |
6 |
Correct |
4 ms |
29276 KB |
Output is correct |
7 |
Correct |
4 ms |
29296 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27228 KB |
Output is correct |
10 |
Correct |
4 ms |
27228 KB |
Output is correct |
11 |
Correct |
8 ms |
29292 KB |
Output is correct |
12 |
Correct |
7 ms |
29276 KB |
Output is correct |
13 |
Correct |
8 ms |
29324 KB |
Output is correct |
14 |
Correct |
9 ms |
29476 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
27228 KB |
Output is correct |
17 |
Correct |
6 ms |
27228 KB |
Output is correct |
18 |
Correct |
5 ms |
27244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
747 ms |
65452 KB |
Output is correct |
2 |
Correct |
742 ms |
65376 KB |
Output is correct |
3 |
Correct |
800 ms |
65364 KB |
Output is correct |
4 |
Correct |
715 ms |
65364 KB |
Output is correct |
5 |
Correct |
625 ms |
57172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
33620 KB |
Output is correct |
2 |
Correct |
50 ms |
33364 KB |
Output is correct |
3 |
Correct |
46 ms |
31572 KB |
Output is correct |
4 |
Correct |
47 ms |
31572 KB |
Output is correct |
5 |
Correct |
50 ms |
31580 KB |
Output is correct |
6 |
Correct |
38 ms |
33112 KB |
Output is correct |
7 |
Correct |
38 ms |
33140 KB |
Output is correct |
8 |
Correct |
43 ms |
31640 KB |
Output is correct |
9 |
Correct |
29 ms |
28948 KB |
Output is correct |
10 |
Correct |
44 ms |
31632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
4 ms |
27228 KB |
Output is correct |
3 |
Correct |
5 ms |
29272 KB |
Output is correct |
4 |
Correct |
4 ms |
29276 KB |
Output is correct |
5 |
Correct |
4 ms |
29276 KB |
Output is correct |
6 |
Correct |
4 ms |
29276 KB |
Output is correct |
7 |
Correct |
4 ms |
29296 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27228 KB |
Output is correct |
10 |
Correct |
4 ms |
27228 KB |
Output is correct |
11 |
Correct |
8 ms |
29292 KB |
Output is correct |
12 |
Correct |
7 ms |
29276 KB |
Output is correct |
13 |
Correct |
8 ms |
29324 KB |
Output is correct |
14 |
Correct |
9 ms |
29476 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
27228 KB |
Output is correct |
17 |
Correct |
6 ms |
27228 KB |
Output is correct |
18 |
Correct |
5 ms |
27244 KB |
Output is correct |
19 |
Correct |
129 ms |
38064 KB |
Output is correct |
20 |
Correct |
116 ms |
37968 KB |
Output is correct |
21 |
Correct |
106 ms |
37456 KB |
Output is correct |
22 |
Correct |
110 ms |
37464 KB |
Output is correct |
23 |
Correct |
107 ms |
37364 KB |
Output is correct |
24 |
Correct |
106 ms |
33368 KB |
Output is correct |
25 |
Correct |
98 ms |
33312 KB |
Output is correct |
26 |
Correct |
104 ms |
33624 KB |
Output is correct |
27 |
Correct |
100 ms |
33564 KB |
Output is correct |
28 |
Correct |
97 ms |
33620 KB |
Output is correct |
29 |
Correct |
103 ms |
33876 KB |
Output is correct |
30 |
Correct |
104 ms |
33880 KB |
Output is correct |
31 |
Correct |
104 ms |
33876 KB |
Output is correct |
32 |
Correct |
105 ms |
33740 KB |
Output is correct |
33 |
Correct |
102 ms |
33960 KB |
Output is correct |
34 |
Correct |
80 ms |
35152 KB |
Output is correct |
35 |
Correct |
85 ms |
35156 KB |
Output is correct |
36 |
Correct |
81 ms |
35032 KB |
Output is correct |
37 |
Correct |
79 ms |
35156 KB |
Output is correct |
38 |
Correct |
82 ms |
34900 KB |
Output is correct |
39 |
Correct |
91 ms |
34316 KB |
Output is correct |
40 |
Correct |
77 ms |
33160 KB |
Output is correct |
41 |
Correct |
110 ms |
33804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
4 ms |
27228 KB |
Output is correct |
3 |
Correct |
5 ms |
29272 KB |
Output is correct |
4 |
Correct |
4 ms |
29276 KB |
Output is correct |
5 |
Correct |
4 ms |
29276 KB |
Output is correct |
6 |
Correct |
4 ms |
29276 KB |
Output is correct |
7 |
Correct |
4 ms |
29296 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27228 KB |
Output is correct |
10 |
Correct |
4 ms |
27228 KB |
Output is correct |
11 |
Correct |
8 ms |
29292 KB |
Output is correct |
12 |
Correct |
7 ms |
29276 KB |
Output is correct |
13 |
Correct |
8 ms |
29324 KB |
Output is correct |
14 |
Correct |
9 ms |
29476 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
27228 KB |
Output is correct |
17 |
Correct |
6 ms |
27228 KB |
Output is correct |
18 |
Correct |
5 ms |
27244 KB |
Output is correct |
19 |
Correct |
747 ms |
65452 KB |
Output is correct |
20 |
Correct |
742 ms |
65376 KB |
Output is correct |
21 |
Correct |
800 ms |
65364 KB |
Output is correct |
22 |
Correct |
715 ms |
65364 KB |
Output is correct |
23 |
Correct |
625 ms |
57172 KB |
Output is correct |
24 |
Correct |
53 ms |
33620 KB |
Output is correct |
25 |
Correct |
50 ms |
33364 KB |
Output is correct |
26 |
Correct |
46 ms |
31572 KB |
Output is correct |
27 |
Correct |
47 ms |
31572 KB |
Output is correct |
28 |
Correct |
50 ms |
31580 KB |
Output is correct |
29 |
Correct |
38 ms |
33112 KB |
Output is correct |
30 |
Correct |
38 ms |
33140 KB |
Output is correct |
31 |
Correct |
43 ms |
31640 KB |
Output is correct |
32 |
Correct |
29 ms |
28948 KB |
Output is correct |
33 |
Correct |
44 ms |
31632 KB |
Output is correct |
34 |
Correct |
129 ms |
38064 KB |
Output is correct |
35 |
Correct |
116 ms |
37968 KB |
Output is correct |
36 |
Correct |
106 ms |
37456 KB |
Output is correct |
37 |
Correct |
110 ms |
37464 KB |
Output is correct |
38 |
Correct |
107 ms |
37364 KB |
Output is correct |
39 |
Correct |
106 ms |
33368 KB |
Output is correct |
40 |
Correct |
98 ms |
33312 KB |
Output is correct |
41 |
Correct |
104 ms |
33624 KB |
Output is correct |
42 |
Correct |
100 ms |
33564 KB |
Output is correct |
43 |
Correct |
97 ms |
33620 KB |
Output is correct |
44 |
Correct |
103 ms |
33876 KB |
Output is correct |
45 |
Correct |
104 ms |
33880 KB |
Output is correct |
46 |
Correct |
104 ms |
33876 KB |
Output is correct |
47 |
Correct |
105 ms |
33740 KB |
Output is correct |
48 |
Correct |
102 ms |
33960 KB |
Output is correct |
49 |
Correct |
80 ms |
35152 KB |
Output is correct |
50 |
Correct |
85 ms |
35156 KB |
Output is correct |
51 |
Correct |
81 ms |
35032 KB |
Output is correct |
52 |
Correct |
79 ms |
35156 KB |
Output is correct |
53 |
Correct |
82 ms |
34900 KB |
Output is correct |
54 |
Correct |
91 ms |
34316 KB |
Output is correct |
55 |
Correct |
77 ms |
33160 KB |
Output is correct |
56 |
Correct |
110 ms |
33804 KB |
Output is correct |
57 |
Correct |
687 ms |
64852 KB |
Output is correct |
58 |
Correct |
681 ms |
64828 KB |
Output is correct |
59 |
Correct |
630 ms |
63400 KB |
Output is correct |
60 |
Correct |
642 ms |
64848 KB |
Output is correct |
61 |
Correct |
631 ms |
63532 KB |
Output is correct |
62 |
Correct |
633 ms |
63316 KB |
Output is correct |
63 |
Correct |
430 ms |
53812 KB |
Output is correct |
64 |
Correct |
442 ms |
53844 KB |
Output is correct |
65 |
Correct |
566 ms |
55124 KB |
Output is correct |
66 |
Correct |
543 ms |
55120 KB |
Output is correct |
67 |
Correct |
533 ms |
55124 KB |
Output is correct |
68 |
Correct |
572 ms |
56660 KB |
Output is correct |
69 |
Correct |
641 ms |
56656 KB |
Output is correct |
70 |
Correct |
588 ms |
56404 KB |
Output is correct |
71 |
Correct |
591 ms |
56496 KB |
Output is correct |
72 |
Correct |
618 ms |
56496 KB |
Output is correct |
73 |
Correct |
400 ms |
54864 KB |
Output is correct |
74 |
Correct |
414 ms |
54828 KB |
Output is correct |
75 |
Correct |
412 ms |
54956 KB |
Output is correct |
76 |
Correct |
408 ms |
54956 KB |
Output is correct |
77 |
Correct |
409 ms |
54608 KB |
Output is correct |
78 |
Correct |
525 ms |
57596 KB |
Output is correct |
79 |
Correct |
429 ms |
51188 KB |
Output is correct |
80 |
Correct |
552 ms |
56656 KB |
Output is correct |