Submission #162780

#TimeUsernameProblemLanguageResultExecution timeMemory
162780abacabaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3059 ms237784 KiB
#include <chrono> #include <random> #include <iostream> #include <string> #include <unordered_map> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> #define tm abc mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 1e9 + 7; const int inf = 1e9; const int N = 1e6 + 15; int n, m, a[N], maxx[N << 2], ans[N]; vector <int> t[N << 2]; struct query { int l, r, k, ind; bool operator < (const query &b) const { return l < b.l; } } qs[N]; void build(int v, int tl, int tr) { if(tl == tr) { t[v] = {a[tl]}; return; } int mid = tl + tr >> 1, l = v << 1, r = v << 1 | 1; build(v << 1, tl, mid); build(v << 1 | 1, mid + 1, tr); maxx[v] = max(maxx[v << 1], maxx[v << 1 | 1]); int i = 0, j = 0; for(; i < t[l].size(); ++i) { if(j && t[l][i] > t[r][j - 1]) maxx[v] = max(maxx[v], t[r][j-1] + t[l][i]); while(j < t[r].size() && t[r][j] < t[l][i]) { maxx[v] = max(maxx[v], t[r][j] + t[l][i]); t[v].pb(t[r][j++]); } t[v].pb(t[l][i]); } while(j < t[r].size()) t[v].pb(t[r][j++]); } int getless(int v, int tl, int tr, int l, int r, int k) { if(tl > r || tr < l) return 0; if(tl >= l && tr <= r) { int ind = lower_bound(t[v].begin(), t[v].end(), k) - t[v].begin(); if(ind) return t[v][ind - 1]; return 0; } int mid = tl + tr >> 1; return max(getless(v << 1, tl, mid, l, r, k), getless(v << 1 | 1, mid + 1, tr, l, r, k)); } int get(int v, int tl, int tr, int l, int r) { if(tl > r || tr < l) return 0; if(tl >= l && tr <= r) return maxx[v]; int mid = tl + tr >> 1, ans = 0; if(tl >= l && mid <= r && !t[v << 1].empty()) { int x = getless(v << 1 | 1, mid + 1, tr, l, r, t[v << 1].back()); if(x) ans = x + t[v << 1].back(); } return max3(ans, get(v << 1, tl, mid, l, r), get(v << 1 | 1, mid + 1, tr, l, r)); } main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); build(1, 1, n); for(int i = 1; i <= m; ++i) { int l, r, k; scanf("%d%d%d", &l, &r, &k); puts(get(1, 1, n, l, r) > k ? "0" : "1"); } return 0; }

Compilation message (stderr)

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:60:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1, l = v << 1, r = v << 1 | 1;
               ~~~^~~~
sortbooks.cpp:65:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(; i < t[l].size(); ++i) {
           ~~^~~~~~~~~~~~~
sortbooks.cpp:68:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < t[r].size() && t[r][j] < t[l][i]) {
               ~~^~~~~~~~~~~~~
sortbooks.cpp:74:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j < t[r].size())
           ~~^~~~~~~~~~~~~
sortbooks.cpp: In function 'int getless(int, int, int, int, int, int)':
sortbooks.cpp:87:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1;
               ~~~^~~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:96:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1, ans = 0;
               ~~~^~~~
sortbooks.cpp: At global scope:
sortbooks.cpp:105:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:106:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &l, &r, &k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...