Submission #1040417

#TimeUsernameProblemLanguageResultExecution timeMemory
1040417vjudge1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
871 ms94032 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(a)              a.begin(), a.end()
#define Base                311
#define endl                '\n'
#define fi                  first
#define fii(i, a, b)        for(int i = a; i <= b; i++)
#define fid(i, a, b)        for(int i = a; i >= b; i--)
#define fill(a,n)           memset(a, n, sizeof(a));
#define getbit(i, j)        ((i >> j) & 1)
#define minimize(x, y)      x = (x > y ? y : x)
#define maximize(x, y)      x = (x < y ? y : x)
#define ins                 insert
#define int                 long long
#define ll                  long long
#define maxn                1000006 
#define MOD                 1000000007
#define name                "file"
#define pb                  push_back
#define pii                 pair< int, int >
#define pll                 pair< long long , long long >
#define re                  return
#define sz(x)               int(x.size())
#define se                  second
#define ull                 unsigned long long

void ctime () { 
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock () / CLOCKS_PER_SEC << "ms\n" ;        
}

void iof () { 
    if ( fopen ( name ".inp" , "r" )) 
    {
        freopen ( name ".inp" , "r" , stdin ); 
        freopen ( name ".out" , "w", stdout );
    }
    ios_base :: sync_with_stdio ( 0 );
    cin . tie ( NULL ), cout . tie ( NULL );
}

struct ddata {
    ll pos, id, k;
};

vector<ddata> ques[maxn];
ll T[4 * maxn];
ll a[maxn];
ll ans[maxn];
void update(int id, int l, int r, int pos, ll val)
{
    if (l > pos || r < pos) re;
    if (l == r) 
    {
        T[id] = val;
        re;
    }
    int mid = (l + r) / 2;
    update(id * 2, l, mid, pos, val);
    update(id * 2 + 1, mid + 1, r, pos, val);
    T[id] = max(T[id * 2], T[id * 2 + 1]);
}

ll get(int id, int l, int r, int u, int v)
{
    if (u > r || l > v) re 0;
    if (l >= u && r <= v) re T[id];
    int mid = (l + r) / 2;
    re max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}

signed main(){
    iof();
    int n, m;
    cin >> n >> m;
    fii(i, 1, n) 
        cin >> a[i];

    fii(i, 1, m)
    {
        ll l, r, val;
        cin >> l >> r >> val;
        ques[r].pb({l, i, val});
    }
    stack<ll> st;
    fii(i, 1, n)
    {
        while(!st.empty() && a[st.top()] <= a[i]) st.pop();
        if (st.size()) update(1, 1, n, st.top(), a[st.top()] + a[i]);
        st.push(i);
        for(auto x : ques[i])
        {
            int l = x.pos, id = x.id, k = x.k;
            if (get(1, 1, n, l, i) <= k) ans[id] = 1;
            else ans[id] = 0;
        }
    }
    fii(i, 1, m) cout << ans[i] << endl;
    ctime();
    re 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen ( name ".inp" , "r" , stdin );
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen ( name ".out" , "w", stdout );
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...