/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 1000508;
#define _getchar_nolock getchar
char readchar() {
char c = _getchar_nolock();
while (c <= 33) {
c = _getchar_nolock();
}
return c;
}
int readint() {
char c = _getchar_nolock();
while (c <= 33) {
c = _getchar_nolock();
}
bool sign = false;
if (c == '-') {
sign = true;
c = _getchar_nolock();
}
int t = 0;
while (c >= '0' && c <= '9') {
t = (t << 3) + (t << 1) + c - '0';
c = _getchar_nolock();
}
return (sign ? -t: t);
}
int n, k;
int a[MAXN];
int fen[MAXN];
int ans[MAXN];
void inc(int i, int val) {
fen[i] = val;
for (int j = i; j < n; j |= (j + 1)) {
chkmax(fen[j], val);
}
}
int get(int i) {
int res = 0;
for (int j = i; j >= 0; j = (j & (j + 1)) - 1) {
chkmax(res, fen[j]);
}
return res;
}
vector<pair<pair<int, int>, int> > z[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// read(FILENAME);
n = readint(), k = readint();
for (int i = 0; i < n; i++) {
a[i] = readint();
}
vector<int> g;
vector<pair<int, int> > kek;
for (int i = 0; i < n; i++) {
while (!g.empty() && a[g.back()] <= a[i]) {
g.pop_back();
}
if (!g.empty()) {
kek.pb({g.back(), i});
}
g.pb(i);
}
sort(all(kek));
for (int i = 0; i < k; i++) {
int l = readint(), r = readint(), x = readint();
z[l - 1].pb({{r - 1, x}, i});
}
int uk = sz(kek) - 1;
for (int i = n - 1; i >= 0; i--) {
while (uk >= 0 && kek[uk].first >= i) {
inc(kek[uk].second, a[kek[uk].first] + a[kek[uk].second]);
uk--;
}
for (auto x: z[i]) {
ans[x.second] = get(x.first.first) <= x.first.second;
}
}
for (int i = 0; i < k; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
22 ms |
23928 KB |
Output is correct |
9 |
Correct |
22 ms |
23800 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
22 ms |
23928 KB |
Output is correct |
9 |
Correct |
22 ms |
23800 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
24056 KB |
Output is correct |
12 |
Correct |
24 ms |
24056 KB |
Output is correct |
13 |
Correct |
25 ms |
24056 KB |
Output is correct |
14 |
Correct |
27 ms |
24156 KB |
Output is correct |
15 |
Correct |
27 ms |
24056 KB |
Output is correct |
16 |
Correct |
24 ms |
24056 KB |
Output is correct |
17 |
Correct |
25 ms |
24056 KB |
Output is correct |
18 |
Correct |
25 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1090 ms |
67332 KB |
Output is correct |
2 |
Correct |
1203 ms |
67236 KB |
Output is correct |
3 |
Correct |
1121 ms |
67284 KB |
Output is correct |
4 |
Correct |
1201 ms |
67204 KB |
Output is correct |
5 |
Correct |
990 ms |
55496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
28272 KB |
Output is correct |
2 |
Correct |
86 ms |
27988 KB |
Output is correct |
3 |
Correct |
82 ms |
26972 KB |
Output is correct |
4 |
Correct |
82 ms |
27000 KB |
Output is correct |
5 |
Correct |
82 ms |
27068 KB |
Output is correct |
6 |
Correct |
64 ms |
26616 KB |
Output is correct |
7 |
Correct |
64 ms |
26616 KB |
Output is correct |
8 |
Correct |
75 ms |
27924 KB |
Output is correct |
9 |
Correct |
54 ms |
26032 KB |
Output is correct |
10 |
Correct |
76 ms |
27344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
22 ms |
23928 KB |
Output is correct |
9 |
Correct |
22 ms |
23800 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
24056 KB |
Output is correct |
12 |
Correct |
24 ms |
24056 KB |
Output is correct |
13 |
Correct |
25 ms |
24056 KB |
Output is correct |
14 |
Correct |
27 ms |
24156 KB |
Output is correct |
15 |
Correct |
27 ms |
24056 KB |
Output is correct |
16 |
Correct |
24 ms |
24056 KB |
Output is correct |
17 |
Correct |
25 ms |
24056 KB |
Output is correct |
18 |
Correct |
25 ms |
24056 KB |
Output is correct |
19 |
Correct |
238 ms |
32696 KB |
Output is correct |
20 |
Correct |
218 ms |
32684 KB |
Output is correct |
21 |
Correct |
186 ms |
32332 KB |
Output is correct |
22 |
Correct |
187 ms |
32308 KB |
Output is correct |
23 |
Correct |
189 ms |
32236 KB |
Output is correct |
24 |
Correct |
159 ms |
29796 KB |
Output is correct |
25 |
Correct |
156 ms |
29816 KB |
Output is correct |
26 |
Correct |
176 ms |
29872 KB |
Output is correct |
27 |
Correct |
179 ms |
29944 KB |
Output is correct |
28 |
Correct |
182 ms |
29944 KB |
Output is correct |
29 |
Correct |
190 ms |
30328 KB |
Output is correct |
30 |
Correct |
196 ms |
30300 KB |
Output is correct |
31 |
Correct |
190 ms |
30456 KB |
Output is correct |
32 |
Correct |
191 ms |
30200 KB |
Output is correct |
33 |
Correct |
201 ms |
30328 KB |
Output is correct |
34 |
Correct |
143 ms |
29176 KB |
Output is correct |
35 |
Correct |
142 ms |
29100 KB |
Output is correct |
36 |
Correct |
139 ms |
29200 KB |
Output is correct |
37 |
Correct |
140 ms |
29060 KB |
Output is correct |
38 |
Correct |
149 ms |
29180 KB |
Output is correct |
39 |
Correct |
167 ms |
30420 KB |
Output is correct |
40 |
Correct |
134 ms |
29388 KB |
Output is correct |
41 |
Correct |
158 ms |
30872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
22 ms |
23928 KB |
Output is correct |
9 |
Correct |
22 ms |
23800 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
24056 KB |
Output is correct |
12 |
Correct |
24 ms |
24056 KB |
Output is correct |
13 |
Correct |
25 ms |
24056 KB |
Output is correct |
14 |
Correct |
27 ms |
24156 KB |
Output is correct |
15 |
Correct |
27 ms |
24056 KB |
Output is correct |
16 |
Correct |
24 ms |
24056 KB |
Output is correct |
17 |
Correct |
25 ms |
24056 KB |
Output is correct |
18 |
Correct |
25 ms |
24056 KB |
Output is correct |
19 |
Correct |
1090 ms |
67332 KB |
Output is correct |
20 |
Correct |
1203 ms |
67236 KB |
Output is correct |
21 |
Correct |
1121 ms |
67284 KB |
Output is correct |
22 |
Correct |
1201 ms |
67204 KB |
Output is correct |
23 |
Correct |
990 ms |
55496 KB |
Output is correct |
24 |
Correct |
92 ms |
28272 KB |
Output is correct |
25 |
Correct |
86 ms |
27988 KB |
Output is correct |
26 |
Correct |
82 ms |
26972 KB |
Output is correct |
27 |
Correct |
82 ms |
27000 KB |
Output is correct |
28 |
Correct |
82 ms |
27068 KB |
Output is correct |
29 |
Correct |
64 ms |
26616 KB |
Output is correct |
30 |
Correct |
64 ms |
26616 KB |
Output is correct |
31 |
Correct |
75 ms |
27924 KB |
Output is correct |
32 |
Correct |
54 ms |
26032 KB |
Output is correct |
33 |
Correct |
76 ms |
27344 KB |
Output is correct |
34 |
Correct |
238 ms |
32696 KB |
Output is correct |
35 |
Correct |
218 ms |
32684 KB |
Output is correct |
36 |
Correct |
186 ms |
32332 KB |
Output is correct |
37 |
Correct |
187 ms |
32308 KB |
Output is correct |
38 |
Correct |
189 ms |
32236 KB |
Output is correct |
39 |
Correct |
159 ms |
29796 KB |
Output is correct |
40 |
Correct |
156 ms |
29816 KB |
Output is correct |
41 |
Correct |
176 ms |
29872 KB |
Output is correct |
42 |
Correct |
179 ms |
29944 KB |
Output is correct |
43 |
Correct |
182 ms |
29944 KB |
Output is correct |
44 |
Correct |
190 ms |
30328 KB |
Output is correct |
45 |
Correct |
196 ms |
30300 KB |
Output is correct |
46 |
Correct |
190 ms |
30456 KB |
Output is correct |
47 |
Correct |
191 ms |
30200 KB |
Output is correct |
48 |
Correct |
201 ms |
30328 KB |
Output is correct |
49 |
Correct |
143 ms |
29176 KB |
Output is correct |
50 |
Correct |
142 ms |
29100 KB |
Output is correct |
51 |
Correct |
139 ms |
29200 KB |
Output is correct |
52 |
Correct |
140 ms |
29060 KB |
Output is correct |
53 |
Correct |
149 ms |
29180 KB |
Output is correct |
54 |
Correct |
167 ms |
30420 KB |
Output is correct |
55 |
Correct |
134 ms |
29388 KB |
Output is correct |
56 |
Correct |
158 ms |
30872 KB |
Output is correct |
57 |
Correct |
1143 ms |
68032 KB |
Output is correct |
58 |
Correct |
1145 ms |
68004 KB |
Output is correct |
59 |
Correct |
1103 ms |
65916 KB |
Output is correct |
60 |
Correct |
1104 ms |
65948 KB |
Output is correct |
61 |
Correct |
1097 ms |
65980 KB |
Output is correct |
62 |
Correct |
1106 ms |
66072 KB |
Output is correct |
63 |
Correct |
690 ms |
50448 KB |
Output is correct |
64 |
Correct |
673 ms |
50296 KB |
Output is correct |
65 |
Correct |
998 ms |
54192 KB |
Output is correct |
66 |
Correct |
973 ms |
54332 KB |
Output is correct |
67 |
Correct |
967 ms |
54364 KB |
Output is correct |
68 |
Correct |
1016 ms |
56432 KB |
Output is correct |
69 |
Correct |
1008 ms |
56236 KB |
Output is correct |
70 |
Correct |
1022 ms |
55876 KB |
Output is correct |
71 |
Correct |
1010 ms |
55728 KB |
Output is correct |
72 |
Correct |
1008 ms |
55768 KB |
Output is correct |
73 |
Correct |
617 ms |
49636 KB |
Output is correct |
74 |
Correct |
633 ms |
49580 KB |
Output is correct |
75 |
Correct |
616 ms |
49400 KB |
Output is correct |
76 |
Correct |
618 ms |
49308 KB |
Output is correct |
77 |
Correct |
615 ms |
49528 KB |
Output is correct |
78 |
Correct |
830 ms |
56244 KB |
Output is correct |
79 |
Correct |
657 ms |
49880 KB |
Output is correct |
80 |
Correct |
785 ms |
61144 KB |
Output is correct |