제출 #1127922

#제출 시각아이디문제언어결과실행 시간메모리
1127922Mikael639Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
1313 ms146280 KiB
#include <bits/stdc++.h> #define fi first #define se second #define For(i, a, b) for (int i = (a); i <= (b); ++i) #define ForD(i, a, b) for (int i = (a); i >= (b); --i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repD(i, n) for (int i = (n) - 1; i >= 0; --i) #define coutE(x) {cout << x << '\n'; return;} #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define bs binary_search #define ub upper_bound #define lb lower_bound #define endl '\n' #define db long double #define ll long long #define vi vector<int> #define vii vector<ii> #define int long long using namespace std; void file(string s){ if (s.empty()) return; freopen((s + ".inp").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } template <class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return 1; } return 0; } template <class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return 1; } return 0; } mt19937_64 rng(time(0)); const int N = 1e6 + 5; const int MOD = 1e9 + 7; //998244353; const int INF = 1e9; const long long LINF = 1e18; const int dx[] = {1, 0, 0, -1}; const int dy[] = {0, 1, -1, 0}; #define Node pair<int, int> int n, q, a[N]; bool ans[N]; struct query{ int r, k, i; }; vector<query> quer[N]; struct Segment_treeeeeeeeee{ Node st[4 * N]; int lazy[4 * N]; Node Merge(Node a, Node b){ return {max(a.fi, b.fi), max(a.se, b.se)}; } void apply(int id, int x){ st[id].se = st[id].fi + x; } void down(int id){ if (!lazy[id]) return; apply(id << 1, lazy[id]); apply(id << 1 | 1, lazy[id]); lazy[id] = 0; } void build(int id, int l, int r){ if (l == r) return st[id] = {a[l], 0}, void(); int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); st[id] = Merge(st[id << 1], st[id << 1 | 1]); } void update(int id, int l, int r, int u, int v, int w){ if (v < l || r < u) return; if (u <= l && r <= v){ st[id].se = st[id].fi + w; lazy[id] = w; return; } down(id); int mid = (l + r) >> 1; update(id << 1, l, mid, u, v, w); update(id << 1 | 1, mid + 1, r, u, v, w); st[id] = Merge(st[id << 1], st[id << 1 | 1]); } Node get(int id, int l, int r, int u, int v){ if (v < l || r < u) return {0, 0}; if (u <= l && r <= v) return st[id]; down(id); int mid = (l + r) >> 1; return Merge(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v)); } } ST; void solve(){ cin >> n >> q; For(i, 1, n) cin >> a[i]; For(i, 1, q){ int l, r, k; cin >> l >> r >> k; quer[l].pb({r, k, i}); } stack<int> st; ForD(i, n, 1){ while (!st.empty() && a[st.top()] < a[i]) st.pop(); int bound = st.empty() ? n : st.top() - 1; st.push(i); if (i + 1 <= bound) ST.update(1, 1, n, i + 1, bound, a[i]); for (auto [r, k, id]: quer[i]){ ans[id] = ST.get(1, 1, n, i, r).se <= k; } } For(i, 1, q) cout << ans[i] << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); file(""); int T = 1; //cin >> T; while (T--) solve(); return 0; }

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

sortbooks.cpp: In function 'void file(std::string)':
sortbooks.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".inp").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s + ".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...