Submission #1017931

#TimeUsernameProblemLanguageResultExecution timeMemory
1017931codefoxHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
34 / 100
676 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define pipi pair<pii, pii> int N = 1<<19; //20? maybe 18 vector<int> bin(2*N, 0); vector<set<int>> bmm(2*N); int sol = 0; int query(int curr, int l, int r, int a, int b, int mx) { if (l >= b || r <= a) return -1e9; if (a <= l && r <= b) { sol = max(sol, bin[curr]); if (bmm[curr].lower_bound(mx)!= bmm[curr].begin()) { int last = *(--bmm[curr].lower_bound(mx)); sol = max(sol, mx+last); } return *(--bmm[curr].end()); } int m = (l+r)/2; mx = max(mx, query(curr*2, l, m, a, b, mx)); mx = max(mx, query(curr*2+1, m, r, a, b, mx)); return mx; } int main() { int n, q; cin >> n >> q; for (int i = 0; i < n; i++) { int a; cin >> a; bmm[i+N].insert(a); } for (int i = n; i < N; i++) bmm[i+N].insert(1e9); for (int i = N-1; i >0; i--) { for (int ele:bmm[i*2]) bmm[i].insert(ele); for (int ele:bmm[i*2+1]) bmm[i].insert(ele); bin[i] = max(bin[i*2], bin[i*2+1]); int mx = *(--bmm[i*2].end()); if (bmm[i*2+1].lower_bound(mx)!=bmm[i*2+1].begin()) { bin[i] = max(bin[i], mx+*(--bmm[i*2+1].lower_bound(mx))); } } while(q--) { int l, r, mood; cin >> l >> r >> mood; l--; sol=0; query(1, 0, N, l, r, -1e9); if (sol <= mood) cout << "1\n"; else cout << "0\n"; } return 0; }
#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...