Submission #1251610

#TimeUsernameProblemLanguageResultExecution timeMemory
1251610NoLoveHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
989 ms145340 KiB
/** * author : Lăng Trọng Đạt * created: 03-08-2025 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT #define int long long #define f first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define FOR(i, a, b) for (int i = (a); (i) <= (b); (i++)) #define FD(i, lo, up) for (int i = (up); (i) >= (lo); i--) #define si(x) (int)(x.size()) bool mx(int& a, int b) { if (b > a) {a = b; return true;} return false;} bool mi(int& a, int b) { if (b < a) {a = b; return true;} return false;} using pii = pair<int, int>; using vi = vector<int>; const int INF = 1e18 + 5; const int MOD = 1e9 + 7; const int N = 1e6 + 5; int g[N]; bool ans[N]; int n, m, k, q, a, b, c; // int st[4*N]; // void upd(int pos, int val, int v = 1, int l = 1, int r = n) { // if (l > pos or pos > r) return; // else if (l == r) { // mx(st[v], val); // } else { // int mid = (l + r) / 2; // int // } // } int BIT[N]; void upd(int pos, int val) { for (; pos <= n; pos += pos & -pos) mx(BIT[pos], val); } int get(int up) { int res = 0; for (int p = up; p > 0; p -= p & -p) mx(res, BIT[p]); return res; } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("hi.inp", "r")) { freopen("hi.inp", "r", stdin); // freopen("hi.out", "w", stdout); } cin >> n >> q; FOR(i, 1, n) { cin >> g[i]; } vector<vi> p; stack<int> big; FOR(i, 1, n) { while (!big.empty() && g[big.top()] <= g[i]) big.pop(); if (!big.empty()) p.push_back({big.top(), i, g[big.top()] + g[i]}); big.push(i); } FOR(i, 1, q) { cin >> a >> b >> k; p.push_back({a, b, k, i}); // int prv = g[a]; // bool ans = true; // FOR(i, a + 1, b) { // if (g[i] < prv && g[i] + prv > k) ans = false; // mx(prv, g[i]); // } // cout << ans << "\n"; } sort(all(p), [](vi& a, vi& b) -> bool { // {x, y, sum, id (for query)} if (a[0] == b[0]) { if (a[1] == b[1]) return si(a) < si(b); return a[1] < b[1]; } return a[0] > b[0]; }); for (auto v : p) { if (si(v) == 3) { upd(v[1], v[2]); } else { ans[v[3]] = get(v[1]) <= v[2]; } } FOR(i, 1, q) cout << ans[i] << "\n"; }

Compilation message (stderr)

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