#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define EPS 1e-9
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define fi first
#define sc second
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;
void solve() {
int n, m;
vector<ii> in, out;
cin >> n >> m;
vector<int> w(n);
vector<bool> can(m, false);
for(int& v : w) cin >> v;
vector<tuple<int, int, int, int>> query(m);
for(int i = 0; i < m; ++i) {
int l, r, k;
cin >> l >> r >> k;
--l, --r;
query[i] = {r, l, k, i};
}
sort(all(query));
for(int i = 0, j = 0; i < n; ++i) {
ii l(-1, -1);
while(!in.empty() && in.back().sc <= w[i]) {
ii y = in.back();
if(l.sc != -1) {
y.sc += l.sc;
while(!out.empty() && out.back().sc <= y.sc) out.pop_back();
out.pb(y);
}
l = in.back();
in.pop_back();
}
in.pb({i, w[i]});
while(j < m && get<0>(query[j]) == i) {
auto [r, l, k, pos] = query[j++];
auto i = lower_bound(all(in), ii(l, -1));
int mood = 0;
if(in.end() - i >= 2) mood = i->sc + next(i)->sc;
i = lower_bound(all(out), ii(l, -1));
if(i != out.end()) mood = max(mood, i->sc);
can[pos] = mood <= k;
}
}
for(bool x : can) cout << x << '\n';
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
574 ms |
53836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
4428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |