제출 #342151

#제출 시각아이디문제언어결과실행 시간메모리
342151NurstanDuisengalievHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
3086 ms262148 KiB
// Nurstan Duisengaliev // не, не надо меня узнавать /*#pragma GCC target ("avx2") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("O3")*/ #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define ll long long #define all(x) x.begin(), x.end() #define in insert #define mp make_pair #define F first #define S second #define ppf pop_front #define pb push_back #define ppb pop_back #define pf push_front #define pii pair <int, int> #define pll pair <ll, ll> #define boost() ios_base::sync_with_stdio(0), cin.tie(0) #define sz(x) (int)x.size() using namespace std; //using namespace __gnu_pbds; //template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = (int)1e6 + 123; const int mod = (int)1e9 + 7; const ll INF = (ll)1e18 + 1; struct st { int ans, maxi; vector <int> ve; }; st d[N * 4]; int n, q, a[N]; st merge (st f, st s) { st ans; ans.maxi = max (f.maxi, s.maxi); ans.ans = max (f.ans, s.ans); int pos1 = 0, pos2 = 0; while (pos1 < sz (f.ve) || pos2 < sz (s.ve)) { if (pos1 >= sz (f.ve)) ans.ve.pb (s.ve[pos2]), pos2 ++; else if (pos2 >= sz (s.ve)) ans.ve.pb (f.ve[pos1]), pos1 ++; else { if (min (f.ve[pos1], s.ve[pos2]) == f.ve[pos1]) ans.ve.pb (f.ve[pos1]), pos1 ++; else ans.ve.pb (s.ve[pos2]), pos2 ++; } } int x = f.maxi; if (x > s.ve[0]) { int l = 0, r = sz (s.ve) - 1, o = -1; while (l <= r) { int mid = l + r >> 1; if (s.ve[mid] < x) { o = s.ve[mid]; l = mid + 1; } else r = mid - 1; } ans.ans = max (ans.ans, x + o); } return ans; } void build (int v, int l, int r) { if (l == r) { d[v].ans = 0; d[v].maxi = a[l]; d[v].ve.pb (a[l]); return; } int mid = l + r >> 1; build (v * 2, l, mid); build (v * 2 + 1, mid + 1, r); d[v] = merge (d[v * 2], d[v * 2 + 1]); } st get (int v, int l, int r, int nl, int nr) { if (nl > r || l > nr) { st o; o.ans = 0, o.maxi = -1; return o; } if (nl <= l && r <= nr) return d[v]; int mid = l + r >> 1; st f, s; f = get (v * 2, l, mid, nl, nr), s = get (v * 2 + 1, mid + 1, r, nl, nr); if (f.maxi == -1) return s; else if (s.maxi == -1) return f; else return merge (f, s); } void solve () { cin >> n >> q; for (int i = 1; i <= n; i ++) cin >> a[i]; build (1, 1, n); while (q --) { int l, r, k; cin >> l >> r >> k; if (get (1, 1, n, l, r).ans > k) cout << 0 << '\n'; else cout << 1 << '\n'; } } main () { // freopen (".in", "r", stdin); // freopen (".out", "w", stdout); boost (); int TT = 1; // cin >> TT; while (TT --) { solve (); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'st merge(st, st)':
sortbooks.cpp:59:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |    int mid = l + r >> 1;
      |              ~~^~~
sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:77:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |  int mid = l + r >> 1;
      |            ~~^~~
sortbooks.cpp: In function 'st get(int, int, int, int, int)':
sortbooks.cpp:89:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   89 |  int mid = l + r >> 1;
      |            ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:108:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  108 | main () {
      |       ^
#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...