제출 #382148

#제출 시각아이디문제언어결과실행 시간메모리
382148BartolMHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1717 ms67528 KiB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=1e6+50;
const int OFF=(1<<20);

int n, q;
int p[N], sol[N];
int T[2*OFF], levi[N];
vector <ppi> que[N];
vector <int> st;

void update(int pos, int val) {
    pos+=OFF; T[pos]=max(T[pos], val);
    pos/=2;
    while (pos) {
        T[pos]=max(T[pos*2], T[pos*2+1]);
        pos/=2;
    }
}

int query(int a, int b, int pos=1, int lo=0, int hi=OFF) {
    if (lo>=a && hi<=b) return T[pos];
    if (lo>=b || hi<=a) return 0;
    int mid=(lo+hi)/2;
    return max(query(a, b, pos*2, lo, mid), query(a, b, pos*2+1, mid, hi));
}

void solve() {
    for (int i=0; i<n; ++i) {
        while (st.size() && p[st.back()]<=p[i]) st.pop_back();
        levi[i]=st.empty() ? -1 : st.back();
        st.pb(i);
    }
    for (int i=0; i<n; ++i) {
        if (levi[i]!=-1) update(levi[i], p[i]+p[levi[i]]);
        for (ppi pp:que[i]) sol[pp.Y]=query(pp.X.X, i+1)<=pp.X.Y;
    }
    for (int i=0; i<q; ++i) printf("%d\n", sol[i]);
}

void load() {
    scanf("%d %d", &n, &q);
    for (int i=0; i<n; ++i) scanf("%d", &p[i]);
    for (int i=0; i<q; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c); a--; b--;
        que[b].pb(mp(mp(a, c), i));
    }
}

int main() {
    load();
    solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'void load()':
sortbooks.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:56:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     for (int i=0; i<n; ++i) scanf("%d", &p[i]);
      |                             ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |         scanf("%d %d %d", &a, &b, &c); a--; b--;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...