Submission #898169

#TimeUsernameProblemLanguageResultExecution timeMemory
898169vjudge1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
796 ms177716 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define tp3 tuple<int, int, int> const int N = 1e6, L = 20, inf = INT_MAX; int n, m, a[N], bit[N], lg[N], st[L][N]; vector<int> lf[N]; vector<tp3> q[N]; bitset<N> ans; void update(int i, int x) { for (; i < n; i = i | (i + 1)) { bit[i] += x; } } int query(int r) { int x = 0; for (; r >= 0; r = (r & (r + 1)) - 1) { x = max(x, bit[r]); } return x; } int querySt(int l, int r) { int x = lg[r-l+1]; return max(st[x][l], st[x][r - (1 << x) + 1]); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); memset(bit, 0, sizeof(bit)); lg[1] = 0; for (int i = 2; i < N; i++) { lg[i] = lg[i >> 1] + 1; } cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; st[0][i] = a[i]; } for (int i = 0; i < m; i++) { int l, r, k; cin >> l >> r >> k; l--; r--; q[l].push_back(make_tuple(r, k, i)); } for (int j = 1; j < L; j++) { for (int i = 0; i < n; i++) { st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]); } } for (int i = 0; i < n; i++) { int l = -1; int r = i-1; while (l < r) { int mid = (l+r+1)/2; int x = querySt(mid, i-1); if (x > a[i]) l = mid; else r = mid-1; } lf[l].push_back(i); if (l != -1) update(i, a[i]+a[l]); } for (int l = 0; l < n; l++) { for (auto& [r, k, idx] : q[l]) { ans[idx] = (query(r) <= k); } for (int& i : lf[l]) { update(i, -(a[i]+a[l])); } } for (int i = 0; i < m; i++) { cout << ans[i] << "\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...