Submission #286270

#TimeUsernameProblemLanguageResultExecution timeMemory
286270SomeoneUnknownHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3073 ms115064 KiB
#include <bits/stdc++.h> using namespace std; vector<int> bks; struct node{ int lo, hi, mid, heaviestswap, mex, meen; node *lft, *rght; node(int l, int h){ lo = l; hi = h; mid = (l+h)/2; if(l == h){ heaviestswap = 0; mex = meen = bks[l]; }else{ lft = new node(l, mid); rght = new node(mid+1, h); mex = max(lft->mex, rght->mex); meen = min(lft->meen, rght->meen); heaviestswap = max(max(lft->heaviestswap, rght->heaviestswap), mex-meen); } } vector<int> query(int l, int h){ vector<int> res; if(l <= lo && hi <= h){ res.push_back(meen); res.push_back(heaviestswap); res.push_back(mex); return res; } res.push_back(mex); res.push_back(0); res.push_back(meen); int rmin = mex; if(mid < h){ vector<int> qres = rght->query(l, h); res[0] = min(res[0], qres[0]); res[2] = max(res[2], qres[2]); res[1] = max(res[1], qres[1]); } if(l <= mid){ vector<int> qres = lft->query(l, h); res[1] = max(res[1], qres[2]-res[0]); res[1] = max(res[1], qres[1]); res[0] = min(res[0], qres[0]); res[2] = max(res[2], qres[2]); } return res; } } *root; int main(){ int n, q; scanf("%d %d", &n, &q); bks.push_back(0); for(int i = 0; i < n; ++i){ int x; scanf("%d", &x); bks.push_back(x); } root = new node(1, n); for(int i = 0; i < q; ++i){ int l, r, w; scanf("%d %d %d", &l, &r, &w); if(root->query(l,r)[1] > w){ printf("0\n"); }else{ printf("1\n"); } } }

Compilation message (stderr)

sortbooks.cpp: In member function 'std::vector<int> node::query(int, int)':
sortbooks.cpp:36:13: warning: unused variable 'rmin' [-Wunused-variable]
   36 |         int rmin = mex;
      |             ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
sortbooks.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%d %d %d", &l, &r, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...