#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using T = tuple<ll, ll, ll>;
#define int long long
#define Base 41
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 1e6 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int N, Q;
int a[MAX];
//l(i) là thằng gần nhất > a(i) về bên trái mà a(i) + a(l(i)) > K
int leftMost[MAX];
vector<array<int, 3>> que[MAX];
int f[MAX];
void modify(int p, int val){
for ( ; p > 0; p -= p & (-p)) maximize(f[p], val);
}
int query(int p){
int res = 0;
for ( ; p <= N; p += p & (-p)) maximize(res, f[p]);
return res;
}
int ans[MAX];
void Whisper(){
cin >> N >> Q;
for (int i = 1; i <= N; ++i) cin >> a[i];
stack<int> st;
for (int i = 1; i <= N; ++i){
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size()) leftMost[i] = st.top();
st.push(i);
}
for (int i = 1; i <= Q; ++i){
int l, r, k; cin >> l >> r >> k;
que[r].push_back({l, k, i});
}
for (int r = 1; r <= N; ++r){
if (leftMost[r] > 0) modify(leftMost[r], a[leftMost[r]] + a[r]);
for (auto&[l, k, id] : que[r]){
ans[id] = (query(l) <= k);
}
}
FOR(i, 1, Q) cout << ans[i] << "\n";
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
27084 KB |
Output is correct |
2 |
Correct |
9 ms |
26972 KB |
Output is correct |
3 |
Correct |
9 ms |
27144 KB |
Output is correct |
4 |
Correct |
9 ms |
26968 KB |
Output is correct |
5 |
Correct |
8 ms |
26972 KB |
Output is correct |
6 |
Correct |
10 ms |
27144 KB |
Output is correct |
7 |
Correct |
9 ms |
26968 KB |
Output is correct |
8 |
Correct |
8 ms |
26968 KB |
Output is correct |
9 |
Correct |
8 ms |
26968 KB |
Output is correct |
10 |
Correct |
10 ms |
26968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
27084 KB |
Output is correct |
2 |
Correct |
9 ms |
26972 KB |
Output is correct |
3 |
Correct |
9 ms |
27144 KB |
Output is correct |
4 |
Correct |
9 ms |
26968 KB |
Output is correct |
5 |
Correct |
8 ms |
26972 KB |
Output is correct |
6 |
Correct |
10 ms |
27144 KB |
Output is correct |
7 |
Correct |
9 ms |
26968 KB |
Output is correct |
8 |
Correct |
8 ms |
26968 KB |
Output is correct |
9 |
Correct |
8 ms |
26968 KB |
Output is correct |
10 |
Correct |
10 ms |
26968 KB |
Output is correct |
11 |
Correct |
11 ms |
27332 KB |
Output is correct |
12 |
Correct |
11 ms |
29456 KB |
Output is correct |
13 |
Correct |
12 ms |
29280 KB |
Output is correct |
14 |
Correct |
11 ms |
29528 KB |
Output is correct |
15 |
Correct |
11 ms |
29552 KB |
Output is correct |
16 |
Correct |
13 ms |
29528 KB |
Output is correct |
17 |
Correct |
12 ms |
29272 KB |
Output is correct |
18 |
Correct |
11 ms |
29280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
937 ms |
120620 KB |
Output is correct |
2 |
Correct |
986 ms |
122804 KB |
Output is correct |
3 |
Correct |
894 ms |
122528 KB |
Output is correct |
4 |
Correct |
967 ms |
122760 KB |
Output is correct |
5 |
Correct |
825 ms |
110016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
39048 KB |
Output is correct |
2 |
Correct |
54 ms |
39200 KB |
Output is correct |
3 |
Correct |
56 ms |
36016 KB |
Output is correct |
4 |
Correct |
54 ms |
36116 KB |
Output is correct |
5 |
Correct |
54 ms |
36176 KB |
Output is correct |
6 |
Correct |
39 ms |
38224 KB |
Output is correct |
7 |
Correct |
42 ms |
38096 KB |
Output is correct |
8 |
Correct |
49 ms |
37512 KB |
Output is correct |
9 |
Correct |
34 ms |
33568 KB |
Output is correct |
10 |
Correct |
57 ms |
37480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
27084 KB |
Output is correct |
2 |
Correct |
9 ms |
26972 KB |
Output is correct |
3 |
Correct |
9 ms |
27144 KB |
Output is correct |
4 |
Correct |
9 ms |
26968 KB |
Output is correct |
5 |
Correct |
8 ms |
26972 KB |
Output is correct |
6 |
Correct |
10 ms |
27144 KB |
Output is correct |
7 |
Correct |
9 ms |
26968 KB |
Output is correct |
8 |
Correct |
8 ms |
26968 KB |
Output is correct |
9 |
Correct |
8 ms |
26968 KB |
Output is correct |
10 |
Correct |
10 ms |
26968 KB |
Output is correct |
11 |
Correct |
11 ms |
27332 KB |
Output is correct |
12 |
Correct |
11 ms |
29456 KB |
Output is correct |
13 |
Correct |
12 ms |
29280 KB |
Output is correct |
14 |
Correct |
11 ms |
29528 KB |
Output is correct |
15 |
Correct |
11 ms |
29552 KB |
Output is correct |
16 |
Correct |
13 ms |
29528 KB |
Output is correct |
17 |
Correct |
12 ms |
29272 KB |
Output is correct |
18 |
Correct |
11 ms |
29280 KB |
Output is correct |
19 |
Correct |
142 ms |
45508 KB |
Output is correct |
20 |
Correct |
125 ms |
45488 KB |
Output is correct |
21 |
Correct |
106 ms |
46100 KB |
Output is correct |
22 |
Correct |
107 ms |
45908 KB |
Output is correct |
23 |
Correct |
111 ms |
45920 KB |
Output is correct |
24 |
Correct |
93 ms |
42356 KB |
Output is correct |
25 |
Correct |
94 ms |
42564 KB |
Output is correct |
26 |
Correct |
120 ms |
42076 KB |
Output is correct |
27 |
Correct |
114 ms |
42160 KB |
Output is correct |
28 |
Correct |
117 ms |
41980 KB |
Output is correct |
29 |
Correct |
114 ms |
41808 KB |
Output is correct |
30 |
Correct |
125 ms |
41924 KB |
Output is correct |
31 |
Correct |
139 ms |
41888 KB |
Output is correct |
32 |
Correct |
130 ms |
41808 KB |
Output is correct |
33 |
Correct |
140 ms |
41924 KB |
Output is correct |
34 |
Correct |
96 ms |
43772 KB |
Output is correct |
35 |
Correct |
83 ms |
43792 KB |
Output is correct |
36 |
Correct |
101 ms |
43784 KB |
Output is correct |
37 |
Correct |
88 ms |
43860 KB |
Output is correct |
38 |
Correct |
88 ms |
43600 KB |
Output is correct |
39 |
Correct |
125 ms |
43200 KB |
Output is correct |
40 |
Correct |
97 ms |
41724 KB |
Output is correct |
41 |
Correct |
148 ms |
42992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
27084 KB |
Output is correct |
2 |
Correct |
9 ms |
26972 KB |
Output is correct |
3 |
Correct |
9 ms |
27144 KB |
Output is correct |
4 |
Correct |
9 ms |
26968 KB |
Output is correct |
5 |
Correct |
8 ms |
26972 KB |
Output is correct |
6 |
Correct |
10 ms |
27144 KB |
Output is correct |
7 |
Correct |
9 ms |
26968 KB |
Output is correct |
8 |
Correct |
8 ms |
26968 KB |
Output is correct |
9 |
Correct |
8 ms |
26968 KB |
Output is correct |
10 |
Correct |
10 ms |
26968 KB |
Output is correct |
11 |
Correct |
11 ms |
27332 KB |
Output is correct |
12 |
Correct |
11 ms |
29456 KB |
Output is correct |
13 |
Correct |
12 ms |
29280 KB |
Output is correct |
14 |
Correct |
11 ms |
29528 KB |
Output is correct |
15 |
Correct |
11 ms |
29552 KB |
Output is correct |
16 |
Correct |
13 ms |
29528 KB |
Output is correct |
17 |
Correct |
12 ms |
29272 KB |
Output is correct |
18 |
Correct |
11 ms |
29280 KB |
Output is correct |
19 |
Correct |
937 ms |
120620 KB |
Output is correct |
20 |
Correct |
986 ms |
122804 KB |
Output is correct |
21 |
Correct |
894 ms |
122528 KB |
Output is correct |
22 |
Correct |
967 ms |
122760 KB |
Output is correct |
23 |
Correct |
825 ms |
110016 KB |
Output is correct |
24 |
Correct |
62 ms |
39048 KB |
Output is correct |
25 |
Correct |
54 ms |
39200 KB |
Output is correct |
26 |
Correct |
56 ms |
36016 KB |
Output is correct |
27 |
Correct |
54 ms |
36116 KB |
Output is correct |
28 |
Correct |
54 ms |
36176 KB |
Output is correct |
29 |
Correct |
39 ms |
38224 KB |
Output is correct |
30 |
Correct |
42 ms |
38096 KB |
Output is correct |
31 |
Correct |
49 ms |
37512 KB |
Output is correct |
32 |
Correct |
34 ms |
33568 KB |
Output is correct |
33 |
Correct |
57 ms |
37480 KB |
Output is correct |
34 |
Correct |
142 ms |
45508 KB |
Output is correct |
35 |
Correct |
125 ms |
45488 KB |
Output is correct |
36 |
Correct |
106 ms |
46100 KB |
Output is correct |
37 |
Correct |
107 ms |
45908 KB |
Output is correct |
38 |
Correct |
111 ms |
45920 KB |
Output is correct |
39 |
Correct |
93 ms |
42356 KB |
Output is correct |
40 |
Correct |
94 ms |
42564 KB |
Output is correct |
41 |
Correct |
120 ms |
42076 KB |
Output is correct |
42 |
Correct |
114 ms |
42160 KB |
Output is correct |
43 |
Correct |
117 ms |
41980 KB |
Output is correct |
44 |
Correct |
114 ms |
41808 KB |
Output is correct |
45 |
Correct |
125 ms |
41924 KB |
Output is correct |
46 |
Correct |
139 ms |
41888 KB |
Output is correct |
47 |
Correct |
130 ms |
41808 KB |
Output is correct |
48 |
Correct |
140 ms |
41924 KB |
Output is correct |
49 |
Correct |
96 ms |
43772 KB |
Output is correct |
50 |
Correct |
83 ms |
43792 KB |
Output is correct |
51 |
Correct |
101 ms |
43784 KB |
Output is correct |
52 |
Correct |
88 ms |
43860 KB |
Output is correct |
53 |
Correct |
88 ms |
43600 KB |
Output is correct |
54 |
Correct |
125 ms |
43200 KB |
Output is correct |
55 |
Correct |
97 ms |
41724 KB |
Output is correct |
56 |
Correct |
148 ms |
42992 KB |
Output is correct |
57 |
Correct |
952 ms |
123512 KB |
Output is correct |
58 |
Correct |
966 ms |
123476 KB |
Output is correct |
59 |
Correct |
922 ms |
124272 KB |
Output is correct |
60 |
Correct |
912 ms |
124324 KB |
Output is correct |
61 |
Correct |
930 ms |
124396 KB |
Output is correct |
62 |
Correct |
831 ms |
124000 KB |
Output is correct |
63 |
Correct |
479 ms |
111232 KB |
Output is correct |
64 |
Correct |
481 ms |
111444 KB |
Output is correct |
65 |
Correct |
803 ms |
111416 KB |
Output is correct |
66 |
Correct |
765 ms |
111272 KB |
Output is correct |
67 |
Correct |
893 ms |
111456 KB |
Output is correct |
68 |
Correct |
836 ms |
110676 KB |
Output is correct |
69 |
Correct |
917 ms |
110672 KB |
Output is correct |
70 |
Correct |
881 ms |
110304 KB |
Output is correct |
71 |
Correct |
902 ms |
110768 KB |
Output is correct |
72 |
Correct |
909 ms |
110724 KB |
Output is correct |
73 |
Correct |
414 ms |
107224 KB |
Output is correct |
74 |
Correct |
456 ms |
108148 KB |
Output is correct |
75 |
Correct |
444 ms |
107344 KB |
Output is correct |
76 |
Correct |
477 ms |
107660 KB |
Output is correct |
77 |
Correct |
442 ms |
106976 KB |
Output is correct |
78 |
Correct |
741 ms |
108448 KB |
Output is correct |
79 |
Correct |
588 ms |
95384 KB |
Output is correct |
80 |
Correct |
710 ms |
104644 KB |
Output is correct |