이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
vector<ii> tmp;
while(!in.empty() && in.back().sc <= w[i]) {
tmp.pb(in.back());
in.pop_back();
}
reverse(all(tmp));
for(int j = 0; j < (int)tmp.size() - 1; ++j) {
tmp[j].sc += tmp[j + 1].sc;
while(!out.empty() && out.back().sc <= tmp[j].sc) out.pop_back();
out.pb(tmp[j]);
}
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |