Submission #936946

#TimeUsernameProblemLanguageResultExecution timeMemory
936946VinhLuuHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
854 ms124420 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 1e6 + 5; const int oo = 1e16; const int mod = 1e9 + 7; int n, m, a[N], kq[N]; vector<array<int, 3>> vr[N]; namespace AC{ int st[N << 1]; void update(int i,int x){ i += n - 1; st[i] = max(st[i], x); while(i > 1){ i /= 2; st[i] = max(st[i << 1], st[i << 1|1]); } } int get(int l,int r){ r++; int ret = -oo; for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){ if(l & 1) ret = max(ret, st[l ++]); if(r & 1) ret = max(ret, st[-- r]); } return ret; } void solve(){ stack<int> s; for(int i = 1; i <= n * 2; i ++) st[i] = -oo; for(int i = 1; i <= n; i ++){ while(!s.empty() && a[s.top()] <= a[i]) s.pop(); if(!s.empty()) update(s.top(), a[i] + a[s.top()]); for(auto [id, l, k] : vr[i]) kq[id] = (get(l, i) <= k); s.push(i); } for(int i = 1; i <= m; i ++) cout << kq[i] << "\n"; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n >> m; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= m; i ++){ int l, r, k; cin >> l >> r >> k; vr[r].pb({i, l, k}); } AC :: solve(); }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...