제출 #1287874

#제출 시각아이디문제언어결과실행 시간메모리
1287874azamuraiHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
3094 ms8360 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair #define pb push_back #define Sz(x) (int)x.size() const int N = 1e6 + 5; int n, m, a[N], pref[N]; void solve() { cin >> n >> m; int mx_val = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; mx_val = max(mx_val, a[i]); } vector <int> suf(1005, n + 1); set <int> st[1005]; for (int i = 1; i <= n; i++) { st[a[i]].insert(i); } while (m--) { int l, r, k; cin >> l >> r >> k; if (k >= 2000) { cout << 1 << '\n'; continue; } for (int x = 0; x <= 1000; x++) { auto to = st[x].lower_bound(l); if (to != st[x].end() && *to <= r) suf[x] = *to; else suf[x] = n + 1; } for (int x = 999; x >= 0; x--) { suf[x] = min(suf[x + 1], suf[x]); } int ok = 1; for (int x = 0; x <= 1000; x++) { int R = max(x + 1, k - x + 1); if (R > 1000) continue; auto to = st[x].upper_bound(r); if (to == st[x].begin()) continue; to = prev(to); if (*to < l) continue; if (*to > suf[R]) { ok = 0; break; } } if (ok) cout << 1 << '\n'; else cout << 0 << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for (int T = 1; T <= t; T++) { solve(); cout << '\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...