제출 #1192439

#제출 시각아이디문제언어결과실행 시간메모리
1192439stefanopulosHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
1194 ms63704 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ldb,ldb> pdd; #define ff(i,a,b) for(int i = a; i <= b; i++) #define fb(i,b,a) for(int i = b; i >= a; i--) #define trav(a,x) for(auto& a : x) #define sz(a) (int)(a).size() #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) const int mod = 1000000007; const int inf = 1e9 + 5; const int mxN = 1000005; int n, q; int niz[mxN]; vector<array<int,3>> upit[mxN]; int res[mxN]; int bor[4 * mxN]; void update(int v, int tl, int tr, int pos, int val){ if(tl == tr){ bor[v] = max(bor[v], val); return; } int mid = (tl + tr) / 2; if(pos <= mid)update(v * 2, tl, mid, pos, val); else update(v * 2 + 1, mid + 1, tr, pos, val); bor[v] = max(bor[v * 2], bor[v * 2 + 1]); } int kveri(int v, int tl, int tr, int l, int r){ if(tl > r || l > tr)return 0; if(tl >= l && tr <= r)return bor[v]; int mid = (tl + tr) / 2; return max(kveri(v * 2, tl, mid, l, r), kveri(v * 2 + 1, mid + 1, tr, l, r)); } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> q; ff(i,1,n)cin >> niz[i]; ff(i,1,q){ int l, r, k; cin >> l >> r >> k; upit[r].pb({l, k, i}); } stack<int> stek; ff(i,1,n){ while(sz(stek) && niz[stek.top()] <= niz[i]){ stek.pop(); } if(sz(stek) > 0){ int j = stek.top(); update(1,1,n,j,niz[j] + niz[i]); } stek.push(i); for(auto c : upit[i]){ int l = c[0]; int k = c[1]; int id = c[2]; res[id] = (kveri(1,1,n,l,i) <= k ? 1 : 0); } } ff(i,1,q)cout << res[i] << '\n'; return 0; } /* 5 2 3 5 1 8 2 1 3 6 2 5 3 // probati bojenje sahovski */
#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...