Submission #1097344

#TimeUsernameProblemLanguageResultExecution timeMemory
1097344TrinhKhanhDungHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
542 ms63488 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 1e6 + 10; struct fen{ vector<int> tree; int n; fen(int _n = 0){ n = _n; tree.resize(n + 3, 0); } void upd(int p, int c){ for(; p > 0; p -= p & -p) maximize(tree[p], c); } int get(int p){ int ans = 0; for(; p <= n; p += p & -p) maximize(ans, tree[p]); return ans; } }; const int maxN = 1e6 + 10; int N, Q; int a[maxN], ans[maxN]; vector<array<int, 4>> que; void solve(){ cin >> N >> Q; for(int i = 1; i <= N; i++){ int x; cin >> x; a[i] = x; } for(int i = 1; i <= Q; i++){ int l, r, k; cin >> l >> r >> k; que.push_back({r, l, k, i}); } sort(ALL(que)); fen bit(N); stack<int> st; int j = 0; for(int i = 1; i <= N; i++){ while(sz(st) && a[st.top()] <= a[i]) st.pop(); if(sz(st)) bit.upd(st.top(), a[st.top()] + a[i]); st.push(i); while(j < Q && que[j][0] <= i){ ans[que[j][3]] = (bit.get(que[j][1]) <= que[j][2]); j++; } } for(int i = 1; i <= Q; i++){ cout << ans[i] << '\n'; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("boxes.inp","r",stdin); // freopen("boxes.out","w",stdout); solve(); return 0; }
#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...