제출 #332998

#제출 시각아이디문제언어결과실행 시간메모리
332998BoabaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
3089 ms72276 KiB
#include <iostream> #include <vector> #define ll long long #define Max(a, b) (((a) < (b)) ? (b) : (a)) #pragma GCC optimize ("O3") const int nmax = 1e6 + 5; struct day { int st, dr, ind; ll k; }; ll v[nmax], aint[4*nmax]; int ans[nmax], last[nmax]; std::vector<int>st; std::vector<day>skema[nmax]; void update(int node, int st, int dr, int x, ll val) { if (st == dr and st == x) { aint[node] = Max(aint[node], val); return; } int mij = (st + dr) >> 1; if(x<=mij) update(node << 1, st, mij, x, val); else update(node << 1 | 1, mij + 1, dr, x, val); aint[node] = Max(aint[node << 1], aint[node << 1 | 1]); } ll query(int node, int st, int dr, int x, int y) { if (y<st or x>dr) return 0; if (x <= st and dr <= y) return aint[node]; int mij = (st + dr) >> 1; return Max(query(node << 1, st, mij, x, y), query(node << 1 | 1, mij + 1, dr, x, y)); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n, m; std::cin >> n >> m; for (int i = 1; i <= n; i++) std::cin >> v[i]; st.push_back(n); for (int i = n - 1; i >= 1; i--) { while (!st.empty() and v[st.back()] < v[i]) last[st.back()] = i, st.pop_back(); st.push_back(i); } for (int i = 1; i <= m; i++) { day aux; std::cin >> aux.st >> aux.dr >> aux.k, aux.ind = i; skema[aux.dr].push_back(aux); } for (int i = 1; i <= n; i++) { if (last[i] != 0) update(1, 1, n, last[i], v[i] + v[last[i]]); for (auto aux : skema[i]) ans[aux.ind] = (query(1, 1, n, aux.st, aux.dr) <= aux.k); } for (int i = 1; i <= m; i++) std::cout << ans[i] << "\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...