Submission #937526

#TimeUsernameProblemLanguageResultExecution timeMemory
937526TeemkaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1747 ms92488 KiB
#include "bits/stdc++.h" #define F first #define S second #define ALL(a) a.begin() , a.end() #ifndef ONLINE_JUDGE #define OK cout << __LINE__ << "| "<< "---------------------------OK-----------------------" << endl; #define deb(x) cout << __LINE__ << "| "<< #x << " = " << x << endl; #else #define OK #define deb(x) #endif typedef long double ld; typedef long long ll; using namespace std ; const ll N = 1e6 + 7 ; const ll INF = 1e9; const ll mod = 1e9 + 7 ; const double eps = 1e-9 ; const int dx[] = { 0 , 0 , 1 , -1, 1 , -1 , 1 , -1} , dy[] = {1 , -1 , 0 , 0 , 1 , 1, -1 , -1} ; int n , q, a[N] , ans[N]; struct query{ int l, k , id; }; vector<query> vec[N]; int t[N]; void upd(int v ,int mx){ v = N - v; while(v < N){ t[v] = max(t[v] , mx); v += v & -v; } } int get(int v){ v = N - v; int res = 0; while(v){ res = max(res , t[v]); v -= v & -v; } return res; } void test_solve(int test_index){ cin >> n >> q; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i<= q;i++){ int l ,r ,k; cin >> l >> r >> k; vec[r].push_back({l ,k ,i }); } stack<pair<int,int>> st; for(int i = 1; i <=n; i++){ while(st.size() and st.top().F <= a[i]) st.pop(); if(st.size()) upd(st.top().S , st.top().F + a[i]); for(auto[l , k , id] : vec[i]){ if(get(l) <= k) ans[id] = 1; } st.push({a[i] , i}); } for(int i = 1; i<= q;i++) cout << ans[i] << endl; } signed main(){ ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0); int test = 1; //cin >> test ; for(int i = 1 ; i <= test ; i++){ // cout << "Case " << i << ": " ; test_solve(i) ; } 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...