제출 #673273

#제출 시각아이디문제언어결과실행 시간메모리
673273Alihan_8Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1323 ms148556 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long const int N = 1e6+1, inf = 1e16+1; struct SegTree{ vector <int> T; void re_size(int n){ T.resize(n*4+1); } void upd(int v, int l, int r, int pos, int val){ if ( l == r ){ T[v] = val; return; } int md = (l+r)>>1; if ( pos <= md ) upd(v*2, l, md, pos, val); else upd(v*2+1, md+1, r, pos, val); T[v] = max(T[v*2], T[v*2+1]); } int get(int v, int l, int r, int tl, int tr){ if ( r < tl or l > tr ) return 0; if ( tl <= l and tr >= r ) return T[v]; int md = (l+r)>>1; return max(get(v*2, l, md, tl, tr), get(v*2+1, md+1, r, tl, tr)); } } Tree; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; Tree.re_size(N); vector <int> p(n); for ( auto &i: p ) cin >> i; struct query{ int l, r, k; }; vector <query> q(m); vector <int> g[n+1], res(m); for ( auto &[l, r, k]: q ) cin >> l >> r >> k, l--, r--; for ( int i = 0; i < m; i++ ){ g[q[i].r].pb(i); } stack <int> stk; for ( int i = 0; i < n; i++ ){ while ( !stk.empty() and p[stk.top()] <= p[i] ) stk.pop(); if ( !stk.empty() ){ Tree.upd(1, 0, n-1, stk.top(), p[stk.top()]+p[i]); } for ( auto cur: g[i] ){ auto [l, r, k] = q[cur]; res[cur] = Tree.get(1, 0, n-1, l, r) <= k; } stk.push(i); } for ( auto i: res ) cout << i << ln; cout << '\n'; }

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

sortbooks.cpp: In function 'void IO(std::string)':
sortbooks.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"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...