Submission #1018049

#TimeUsernameProblemLanguageResultExecution timeMemory
1018049codefoxHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2919 ms230296 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define pii pair<int, int> #define pipi pair<pii, pii> const int N = 1<<20; int bin[2*N]; vector<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]); auto u = lower_bound(bmm[curr].begin(), bmm[curr].end(), mx); if (u!= bmm[curr].begin()) { int last = *(--u); sol = max(sol, mx+last); } return bmm[curr].back(); } 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() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; for (int i = 0; i < 2*N;i ++) bin[i]=0; for (int i = 0; i < n; i++) { int a; cin >> a; bmm[i+N].push_back(a); } for (int i = n; i < N; i++) bmm[i+N].push_back(1e9); for (int i = N-1; i >0; i--) { bmm[i] = vector<int>(bmm[i*2]); for (int ele:bmm[i*2+1]) bmm[i].push_back(ele); sort(bmm[i].begin(), bmm[i].end()); bin[i] = max(bin[i*2], bin[i*2+1]); int mx = bmm[i*2].back(); auto u = lower_bound(bmm[i*2+1].begin(), bmm[i*2+1].end(), mx); if (u!=bmm[i*2+1].begin()) { bin[i] = max(bin[i], mx+*(--u)); } } 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...