Submission #154500

#TimeUsernameProblemLanguageResultExecution timeMemory
154500muhammad_hokimiyonHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1784 ms35756 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define fi first #define se second #define LL long long using namespace std; const int N = 1e6 + 7; const LL mod = 1e9 + 7; const int B = sqrt(1e5); int n,q; int a[N]; int l[N]; int r[N]; int k[N]; int ord[N]; int nxt[N]; int t[4 * N]; stack < int > s; void add( int x , int l , int r , int pos , int xx ) { if( !( l <= pos && r >= pos ) )return; t[x] = max( t[x] , xx ); int m = (l + r) / 2; if( l == r )return; add(x * 2 , l , m , pos , x); add(x * 2 + 1 , m + 1 , r , pos , x); } int get( int x , int l , int r , int tl , int tr ) { if( l >= tl && r <= tr )return t[x]; if( l > tr || r < tl )return -1; int m = (l + r) / 2; return max( get(x * 2 , l , m , tl , tr ) , get( x * 2 + 1 , m + 1 , r , tl , tr) ); } bool cmp( int x , int y ){ return r[x] < r[y]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen( "input.txt" , "r" , stdin ); //freopen( "output.txt" , "w" , stdout ); cin >> n >> q; for( int i = 1; i <= n; i++ ){ cin >> a[i]; } for( int i = 1; i <= q; i++ ){ cin >> l[i] >> r[i] >> k[i]; ord[i] = i; } int cnt = 0; sort( ord + 1 , ord + q + 1 , cmp ); for( int i = 1; i <= n; i++ ){ while( !s.empty() && a[s.top()] <= a[i] ){ s.pop(); } if( !s.empty() ){ nxt[i] = s.top(); } s.push(i); } for( int i = 1; i <= q; i++ ){ int y = ord[i]; while( cnt < r[y] ){ cnt++; if( nxt[cnt] > 0 ){ add( 1 , 1 , n , nxt[cnt] , a[nxt[cnt]] + a[cnt] ); } } if( get(1 , 1 , n , l[i] , r[i]) <= k[i] )cout << 1 << "\n"; else cout << 0 << "\n"; } }
#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...