Submission #147805

#TimeUsernameProblemLanguageResultExecution timeMemory
147805leathermanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3035 ms40816 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define ll long long #define ld long double #define endl "\n" #define fi first #define se second #define y1 sadjfskldf #define PB push_back #define sqr(x) ((x) * (x)) #define all(x) x.begin(), x.end() using namespace std; using namespace __gnu_pbds; mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()); const ll N = 1e6 + 100; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct tre { ll val = 0,ans = 0; }; tre t[4 * N]; ll a[N],n,m,l,r,k,x; void build(ll v,ll tl,ll tr) { if(tl == tr) { t[v].val = a[tl]; return; } ll tm = (tl + tr) / 2; build(2 * v, tl, tm); build(2 * v + 1, tm + 1, tr); t[v].ans = max(max(t[2 * v].ans, t[2 * v + 1].ans), (t[2 * v].val + t[2 * v + 1].val) * (t[2 * v].val > t[2 * v + 1].val)); t[v].val = max(t[2 * v].val, t[2 * v + 1].val); // cout<<tl<<" - "<<tr<<" "<<t[v].ans<<" "<<t[v].val<<endl; } tre get(ll v,ll tl,ll tr,ll l,ll r) { if(l > r) { tre pisos; pisos.val = pisos.ans = -1e9; return pisos; }; if(tl == tr) return t[v]; ll tm = (tl + tr) / 2; tre res,x,y; x = get(2 * v, tl, tm, l, min(r, tm)); y = get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r); res.ans = max(max(x.ans, y.ans), (x.val + y.val) * (x.val > y.val)); res.val = max(x.val, y.val); return res; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m; for(int i = 1; i <= n; i++) cin>>a[i]; build(1, 1, n); for(int i = 1; i <= m; i++) { cin>>l>>r>>k; x = get(1, 1, n, l, r).ans; // cout<<l<<" "<<r<<" = "<<x<<endl; if(x > k) cout<<0; else cout<<1<<endl; } 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...