Submission #343647

#TimeUsernameProblemLanguageResultExecution timeMemory
343647PetyHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
622 ms262148 KiB
#include <bits/stdc++.h> using namespace std; int n, m, w[1000002]; struct nodA { int max, inv; vector<int>v; } aint[4000002]; int ans = 0, mx = 0; void build (int nod, int st, int dr) { if (st == dr) { aint[nod].max = w[st]; aint[nod].inv = 0; aint[nod].v.push_back(w[st]); return; } int mid = (st + dr) / 2; build(2 * nod, st, mid); build(2 * nod + 1, mid + 1, dr); aint[nod].inv = max(aint[2 * nod].inv, aint[2 * nod + 1].inv); aint[nod].max = max(aint[2 * nod].max, aint[2 * nod + 1].max); auto it = lower_bound(aint[2 * nod + 1].v.begin(), aint[2 * nod + 1].v.end(), aint[2 * nod].max); if (it != aint[2 * nod + 1].v.begin()) { it--; aint[nod].inv = max(aint[nod].inv, aint[2 * nod].max + *it); } int i = 0, j = 0; while (i < aint[2 * nod].v.size() && j < aint[2 * nod + 1].v.size()) { if (aint[2 * nod].v[i] == aint[2 * nod + 1].v[j]) { int x = aint[2 * nod].v[i]; aint[nod].v.push_back(x); aint[nod].v.push_back(x); i++; j++; } if (aint[2 * nod].v[i] < aint[2 * nod + 1].v[j]) { int x = aint[2 * nod].v[i]; aint[nod].v.push_back(x); i++; } if (aint[2 * nod].v[i] > aint[2 * nod + 1].v[j]) { int x = aint[2 * nod + 1].v[j]; aint[nod].v.push_back(x); j++; } } while (i < aint[2 * nod].v.size()) aint[nod].v.push_back(aint[2 * nod].v[i++]); while (j < aint[2 * nod + 1].v.size()) aint[nod].v.push_back(aint[2 * nod + 1].v[j++]); } void query (int nod, int st, int dr, int a, int b) { if (a <= st && dr <= b) { if (mx == -1) { ans = aint[nod].inv; mx = max(mx, aint[nod].max); } else { ans = max(ans, aint[nod].inv); auto it = lower_bound(aint[nod].v.begin(), aint[nod].v.end(), mx); if (it != aint[nod].v.begin()) { it--; ans = max(ans, mx + *it); } mx = max(mx, aint[nod].max); } return; } int mid = (st + dr) / 2; if (a <= mid) query(2 * nod, st, mid, a, b); if (b > mid) query(2 * nod + 1, mid + 1, dr, a, b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i]; build(1, 1, n); for (int i = 1; i <= m; i++) { int l, r, k; cin >> l >> r >> k; ans = mx = -1; query(1, 1, n, l, r); cout << (ans <= k) << "\n"; } return 0; }

Compilation message (stderr)

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:30:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   while (i < aint[2 * nod].v.size() && j < aint[2 * nod + 1].v.size()) {
      |          ~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:30:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   while (i < aint[2 * nod].v.size() && j < aint[2 * nod + 1].v.size()) {
      |                                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:49:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   while (i < aint[2 * nod].v.size())
      |          ~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:51:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   while (j < aint[2 * nod + 1].v.size())
      |          ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...