Submission #1268766

#TimeUsernameProblemLanguageResultExecution timeMemory
1268766hoa208Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
907 ms83680 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define pa pair<ll, ll> #define fi first #define se second #define bit(mask, j) ((mask >> j) & 1) const ll mod = 1e9 + 7; const ll INF = 1e18; //-------------------------------------------------------------------- const ll N = 1e6 + 10; ll st[4 * N]; ll w[N]; ll n, m; struct query { ll x, k, id; }; vector<query> qr[N]; void update(ll u, ll val, ll id = 1, ll l = 1, ll r = n) { if(u <l || u > r) return; if(l == r) { st[id] = val; return; } ll mid = l + r >> 1; update(u, val, id << 1, l, mid); update(u, val, id << 1 | 1, mid + 1, r); st[id] = max(st[id << 1], st[id << 1 | 1]); } ll get(ll u, ll v, ll id = 1, ll l = 1, ll r = n) { if(u > r || v < l) return -INF; if(u <= l && v >= r) return st[id]; ll mid = l + r >> 1; return max(get(u, v, id << 1, l, mid), get(u, v, id << 1 | 1, mid + 1, r)); } bool ans[N]; void hbmt() { cin >> n >> m; FOR(i, 1, n) { cin >> w[i]; } FOR(i, 1, m) { ll l, r, k; cin >> l >> r >> k; qr[r].push_back({l, k, i}); } stack<ll> st; FOR(i, 1, n) { while(!st.empty() && w[st.top()] <= w[i]) { st.pop(); } if(!st.empty()) { update(st.top(), w[st.top()] + w[i]); // cout << w[st.top()] + w[i] << ' ' << st.top() << ' ' << i << '\n'; } st.push(i); for(auto e : qr[i]) { ll x = get(e.x, i); if(x <= e.k) { ans[e.id] = 1; } } } FOR(i, 1, m) cout << ans[i] << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #define NAME "hbmt" if(fopen(NAME".inp", "r")) { freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } //int t;cin>>t;while(t--) hbmt(); return 0; }

Compilation message (stderr)

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