Submission #172879

#TimeUsernameProblemLanguageResultExecution timeMemory
172879limqHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
873 ms60408 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; #define ll long long #define db double #define pb push_back #define ppb pop_back #define fi first #define se second #define mp make_pair #define size(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define low_b lower_bound #define endl "\n" //#define int long long using namespace std; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair <int, int> pii; const int N = 1000003; int n, m, a[N], l[N]; bool ans[N]; struct qu { int l, r, k, ind; qu(int l = 0, int r = 0, int k = 0, int ind = 0) { this -> l = l; this -> r = r; this -> k = k; this -> ind = ind; } bool operator < (const qu & q) const { return r < q.r; } }; vector <qu> v; set <pii> t; void add(int x) { if (x == 0) { return; } int val = a[x] + a[l[x]]; auto it = t.insert({l[x], val}).fi; if (next(it) != t.end() && (*next(it)).se > val) { t.erase(it); return; } while (it != t.begin() && (*prev(it)).se < val) { t.erase(prev(it)); } } int getmax(int x) { if (t.empty()) { return 0; } auto it = t.lower_bound({x, 0}); if (it == t.end()) { return 0; } return (*it).se; } void solve(int tc) { // check for (int i = 0; i < n; j++) cin >> n >> m; stack <int> st; for (int i = 1; i <= n; i++) { cin >> a[i]; while (!st.empty() && a[st.top()] <= a[i]) { st.pop(); } if (!st.empty()) { l[i] = st.top(); } st.push(i); } int tl, tr, tk; for (int i = 1; i <= m; i++) { cin >> tl >> tr >> tk; v.pb(qu(tl, tr, tk, i)); } sort(all(v)); int j = 1; for (int i = 0; i < m; i++) { while (j <= v[i].r) { add(j); j++; } if (getmax(v[i].l) > v[i].k) { ans[v[i].ind] = true; } } for (int i = 1; i <= m; i++) { if (ans[i]) { cout << "0\n"; } else { cout << "1\n"; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int i = 0; i < tc; i++) { solve(i); // cleanup(); } }
#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...