Submission #1022928

#TimeUsernameProblemLanguageResultExecution timeMemory
1022928hasan2006Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
757 ms153604 KiB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e6 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N] , d[N] , ans[N] ;
vector<int>vc[N];

void add(int x , ll y){
    while(x <= 1000000){
        dp[x] = max(dp[x] , y);
        x += (x & -x);
    }
}
ll get(int x ){
    ll ans = 0;
    while(x > 0){
        ans = max(dp[x] , ans);
        x -= (x & -x);
    }
    return ans;
}

void solve()
{
    ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
    cin>>n>>m;
    vector<pair<int,int>>v;
    set<pair<int,int>>st;
    for(i = 1; i <= n; i++)
        cin>>d[i];
    for(i = n; i >= 1; i--){
        while(st.size() && st.begin()->fi < d[i])
            vc[i].pb(st.begin()->se), st.erase(st.begin());
        st.insert({d[i] , i});
    }
    for(i = 1; i <= m; i++){
        cin>>a[i]>>b[i]>>c[i];
        v.pb({a[i] , i});
    }
    sort(rall(v));
    r = n;
    for(auto to : v){
        i = to.se;
        while(r >= a[i]){
            for(auto x : vc[r])
                add(x , d[x] + d[r]);
            r--;
        }
        ans[i] = (get(b[i]) <= c[i]);
    }
    for(i = 1; i <= m; i++)
        cout<<ans[i]<<"\n";
}

int main(){
    TL;

    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int t = 1;
//    cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن

Compilation message (stderr)

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:42:12: warning: unused variable 'q' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
sortbooks.cpp:42:20: warning: unused variable 'j' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                    ^
sortbooks.cpp:42:23: warning: unused variable 'l' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                       ^
sortbooks.cpp:42:30: warning: unused variable 'x' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                              ^
sortbooks.cpp:42:34: warning: unused variable 'y' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                  ^
sortbooks.cpp:42:38: warning: unused variable 's' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
sortbooks.cpp:42:46: warning: unused variable 'f' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                              ^
sortbooks.cpp:42:50: warning: unused variable 'k' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                  ^
sortbooks.cpp:42:58: warning: unused variable 'mn' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                          ^~
sortbooks.cpp:42:69: warning: unused variable 'mx' [-Wunused-variable]
   42 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 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...