Submission #169471

#TimeUsernameProblemLanguageResultExecution timeMemory
169471abilHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2134 ms107284 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = (1e6 + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); int a[N], pos[N], l[N], r[N], k[N], t[N * 4], ans[N]; vector<int > vec[N]; void update(int v,int tl,int tr,int pos,int val){ if(tl == tr){ t[v] = val; return; } int mid = (tl + tr) >> 1; if(pos <= mid){ update(v + v, tl, mid, pos, val); } else{ update(v + v + 1, mid + 1, tr, pos, val); } t[v] = max(t[v + v], t[v + v + 1]); } int get(int v,int tl,int tr,int ll,int rr){ if(tl > rr || tr < ll){ return 0; } if(ll <= tl && tr <= rr){ return t[v]; } int mid = (tl + tr) >> 1; return max(get(v + v, tl, mid, ll, rr), get(v + v + 1, mid + 1, tr, ll, rr)); } main() { int n, m; scanf("%d%d", &n, &m); for(int i = 1;i <= n; i++){ scanf("%d", &a[i]); pos[i] = i - 1; while(pos[i] && a[pos[i]] <= a[i]){ pos[i] = pos[pos[i]]; } } for(int i = 1;i <= m; i++){ scanf("%d%d%d", &l[i], &r[i], &k[i]); vec[r[i]].pb(i); } for(int i = 1;i <= n; i++){ if(pos[i]){ update(1, 1, n, pos[i], a[i] + a[pos[i]]); } for(auto to : vec[i]){ ans[to] = (get(1, 1, n, l[to], r[to]) <= k[to] ? 1 : 0); } } for(int i = 1;i <= m; i++){ printf("%d\n", ans[i]); } }

Compilation message (stderr)

sortbooks.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l[i], &r[i], &k[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...