제출 #1160113

#제출 시각아이디문제언어결과실행 시간메모리
1160113MPGHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
1682 ms157408 KiB
//#pragma GCC optomize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC target("sse,sse2,sse4.1,sse4.2") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define max_heap priority_queue<pair <ll, pair <ll, ll>>> #define min_heap priority_queue<pair <ll, ll>, vector<pair <ll, ll>>, greater<pair <ll, ll>>> #define sariE cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); #define filE freopen("in.txt", "r", stdin); freopen("out1.txt", "w", stdout); #define endl '\n' #define md(a) (a % mod + mod) % mod #define pb push_back //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //cout << setprecision(5) << fixed << f; //hash prime = 769 ll const maxn = 1e6 + 123; ll const inf = 2e18; ll const loG = 23; //ll const mod = 1e9 + 7; ll const mod = 998244353; ll const sq = 400; ll power(ll a, ll b, ll mod){if(b==0)return 1;if(b==1)return a;ll x = power(a, b / 2, mod);return (((x * x) % mod) * (b % 2 ? a : 1)) % mod;} ll n, q, arr[maxn], chap[maxn], rast[maxn], ans[maxn], K[maxn], sz = 2; vector <pair <ll, ll>> qu[maxn], qu2[maxn]; vector <ll> seg; void setter(ll i, ll val, ll x, ll lx, ll rx){ if (rx - lx == 1){ seg[x] = max(seg[x], val); return; } ll mid = (lx + rx) / 2, a = 2 * x + 1, b = a + 1; if (i < mid) setter(i, val, a, lx, mid); else setter(i, val, b, mid, rx); seg[x] = max(seg[a], seg[b]); } ll get(ll l, ll r, ll x, ll lx, ll rx){ if (l >= rx || lx >= r) return 0; if (l <= lx && rx <= r){ return seg[x]; } ll mid = (lx + rx) / 2, a = 2 * x + 1, b = a + 1; ll val1 = get(l, r, a, lx, mid); ll val2 = get(l, r, b, mid, rx); return max(val1, val2); } void Solve(){ cin >> n >> q; while (sz <= n) sz = sz * 2; seg.resize(2 * sz); for (int i = 1; i < n + 1; i++) cin >> arr[i]; vector <ll> stk; stk.clear(); for (int i = 1; i < n + 1; i++){ while (stk.size() && arr[stk.back()] <= arr[i]){ stk.pop_back(); } if (stk.size()){ chap[i] = stk.back(); } stk.pb(i); } stk.clear(); for (int i = n; i > 0; i--){ while (stk.size() && arr[stk.back()] >= arr[i]) stk.pop_back(); if (stk.size()){ rast[i] = stk.back(); } else rast[i] = n + 1; stk.pb(i); } for (int i = 1; i < q + 1; i++){ ll a, b, c; cin >> a >> b >> K[i]; qu[b].pb({a, i}); qu2[a].pb({b, i}); } for (int i = 1; i < n + 1; i++){ if (chap[i]){ setter(chap[i], arr[chap[i]] + arr[i], 0, 0, sz); } for (auto p : qu[i]){ ans[p.second] = max(ans[p.second], get(p.first, i + 1, 0, 0, sz)); } } for (int i = 0; i < seg.size(); i++) seg[i] = 0; for (int i = n; i > 0; i--){ if (rast[i] < n + 1){ setter(rast[i], arr[rast[i]] + arr[i], 0, 0, sz); } for (auto p : qu2[i]){ ans[p.second] = max(ans[p.second], get(i, p.first + 1, 0, 0, sz)); } } for (int i = 1; i < q + 1; i++){ if (ans[i] <= K[i]) cout << 1 << endl; else cout << 0 << endl; } } int main(){ sariE;// filE; int test = 1; //cin >> test; while (test--) 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...