제출 #928217

#제출 시각아이디문제언어결과실행 시간메모리
928217vjudge1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
30 / 100
376 ms144724 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 1e6 + 5; const int mod = 1e9 + 7; int a[maxn]; int d[5005][5005]; int pref[maxn]; vector <int> b; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (n <= 5000 && m <= 5000) { for (int i = 1; i <= n; i++) { int x = a[i]; for (int j = i + 1; j <= n; j++) { d[i][j] = d[i][j - 1]; x = max(x, a[j]); if (x > a[j]) { d[i][j] = max(d[i][j], x + a[j]); } } } while (m--) { int l, r, k; cin >> l >> r >> k; cout << (d[l][r] <= k) << '\n'; } return 0; } a[0] = 0; b.pb(0); for (int i = 1; i <= n; i++) { if (i > 1) { if (a[i] >= a[i - 1]) b.pb(1); else b.pb(0); } pref[i] = pref[i - 1] + b.back(); // cout << pref[i] << ' '; } while (m--) { int l, r, k; cin >> l >> r >> k; cout << (pref[r] - pref[l] == r - l) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...