답안 #1107932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107932 2024-11-02T11:43:54 Z LilPluton Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
693 ms 70308 KB
#include <bits/stdc++.h>
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
using namespace std;
#define int long long 
#define ld long double
#define ar array
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define pii pair<int,int>
#define all(c) (c).begin(), (c).end()
#define endll   '\n'
#define fastio  ios::sync_with_stdio(0);cin.tie(0);
#define lb(a, x)    lower_bound(all(a), x) - a.begin();
#define ub(a, x)    upper_bound(all(a), x) - a.begin();
template<typename T> bool umax(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool umin(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
mt19937 rng(time(0));
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

const int N = 2e5 + 5;

int n, q;
int a[N], mx[N << 2];
vi st[N << 2];

void build(int node,int l,int r){
    mx[node] = 0;
    if(l == r){
        st[node].pb(a[l]);
        return;
    }
    int mid = (l + r) >> 1;
    build(node * 2, l, mid);
    build(node * 2 + 1, mid + 1, r);
    st[node].resize(st[node * 2].size() + st[node * 2 + 1].size());
    merge(all(st[node * 2]), all(st[node * 2 + 1]), begin(st[node]));
    if(st[node * 2].back() > st[node * 2 + 1][0]){
        mx[node] = st[node * 2].back() + *--lower_bound(st[node * 2 + 1].begin(), st[node * 2 + 1].end(), st[node * 2].back());
    }
    mx[node] = max({mx[node], mx[node * 2], mx[node * 2 + 1]});
}
vi res;
void get(int node,int l,int r,int lx,int rx){
    if(l > rx || r < lx){
        return;
    }
    if(l >= lx && r <= rx){
        res.pb(node);
        return;
    }
    int mid = (l + r) >> 1;
    get(node * 2, l, mid, lx, rx);
    get(node * 2 + 1, mid + 1, r, lx, rx);
}

signed main() {
    fastio
    cin >> n >> q;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    build(1, 1, n);
    while(q--){
        res.clear();
        int l, r, x;
        cin >> l >> r >> x;
        get(1, 1, n, l, r);
        int curmx = 0, ans = 0;
        for(int &i : res){
            umax(ans, mx[i]);
        }
        for(int i = 0; i < res.size() - 1; ++i){
            int l = res[i], r = res[i + 1];
            umax(curmx, st[l].back());
            if(curmx > st[r][0]){
                umax(ans, curmx + *--lower_bound(all(st[r]), curmx));
            }
        }
        cout << (ans <= x) << endl;
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:74:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int i = 0; i < res.size() - 1; ++i){
      |                        ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21072 KB Output is correct
2 Correct 4 ms 21072 KB Output is correct
3 Correct 5 ms 21240 KB Output is correct
4 Correct 4 ms 21092 KB Output is correct
5 Correct 4 ms 21072 KB Output is correct
6 Correct 5 ms 21072 KB Output is correct
7 Correct 5 ms 21072 KB Output is correct
8 Correct 5 ms 21072 KB Output is correct
9 Correct 5 ms 21072 KB Output is correct
10 Correct 5 ms 21072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21072 KB Output is correct
2 Correct 4 ms 21072 KB Output is correct
3 Correct 5 ms 21240 KB Output is correct
4 Correct 4 ms 21092 KB Output is correct
5 Correct 4 ms 21072 KB Output is correct
6 Correct 5 ms 21072 KB Output is correct
7 Correct 5 ms 21072 KB Output is correct
8 Correct 5 ms 21072 KB Output is correct
9 Correct 5 ms 21072 KB Output is correct
10 Correct 5 ms 21072 KB Output is correct
11 Correct 11 ms 21328 KB Output is correct
12 Correct 10 ms 21960 KB Output is correct
13 Correct 11 ms 21840 KB Output is correct
14 Correct 15 ms 22008 KB Output is correct
15 Correct 15 ms 21840 KB Output is correct
16 Correct 14 ms 22020 KB Output is correct
17 Correct 13 ms 21840 KB Output is correct
18 Correct 13 ms 22000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 47688 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 263 ms 43640 KB Output is correct
2 Correct 255 ms 43468 KB Output is correct
3 Correct 247 ms 43592 KB Output is correct
4 Correct 246 ms 43532 KB Output is correct
5 Correct 239 ms 43592 KB Output is correct
6 Correct 227 ms 43376 KB Output is correct
7 Correct 223 ms 43336 KB Output is correct
8 Correct 226 ms 43084 KB Output is correct
9 Correct 181 ms 22604 KB Output is correct
10 Correct 232 ms 43244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21072 KB Output is correct
2 Correct 4 ms 21072 KB Output is correct
3 Correct 5 ms 21240 KB Output is correct
4 Correct 4 ms 21092 KB Output is correct
5 Correct 4 ms 21072 KB Output is correct
6 Correct 5 ms 21072 KB Output is correct
7 Correct 5 ms 21072 KB Output is correct
8 Correct 5 ms 21072 KB Output is correct
9 Correct 5 ms 21072 KB Output is correct
10 Correct 5 ms 21072 KB Output is correct
11 Correct 11 ms 21328 KB Output is correct
12 Correct 10 ms 21960 KB Output is correct
13 Correct 11 ms 21840 KB Output is correct
14 Correct 15 ms 22008 KB Output is correct
15 Correct 15 ms 21840 KB Output is correct
16 Correct 14 ms 22020 KB Output is correct
17 Correct 13 ms 21840 KB Output is correct
18 Correct 13 ms 22000 KB Output is correct
19 Correct 693 ms 70216 KB Output is correct
20 Correct 611 ms 70216 KB Output is correct
21 Correct 573 ms 70016 KB Output is correct
22 Correct 558 ms 70084 KB Output is correct
23 Correct 603 ms 70016 KB Output is correct
24 Correct 478 ms 69832 KB Output is correct
25 Correct 478 ms 69960 KB Output is correct
26 Correct 468 ms 70216 KB Output is correct
27 Correct 476 ms 70028 KB Output is correct
28 Correct 475 ms 70204 KB Output is correct
29 Correct 493 ms 70268 KB Output is correct
30 Correct 511 ms 70140 KB Output is correct
31 Correct 511 ms 70216 KB Output is correct
32 Correct 524 ms 70136 KB Output is correct
33 Correct 530 ms 70308 KB Output is correct
34 Correct 455 ms 69764 KB Output is correct
35 Correct 459 ms 69876 KB Output is correct
36 Correct 462 ms 69604 KB Output is correct
37 Correct 454 ms 69652 KB Output is correct
38 Correct 467 ms 69692 KB Output is correct
39 Correct 498 ms 68680 KB Output is correct
40 Correct 445 ms 52624 KB Output is correct
41 Correct 472 ms 68424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21072 KB Output is correct
2 Correct 4 ms 21072 KB Output is correct
3 Correct 5 ms 21240 KB Output is correct
4 Correct 4 ms 21092 KB Output is correct
5 Correct 4 ms 21072 KB Output is correct
6 Correct 5 ms 21072 KB Output is correct
7 Correct 5 ms 21072 KB Output is correct
8 Correct 5 ms 21072 KB Output is correct
9 Correct 5 ms 21072 KB Output is correct
10 Correct 5 ms 21072 KB Output is correct
11 Correct 11 ms 21328 KB Output is correct
12 Correct 10 ms 21960 KB Output is correct
13 Correct 11 ms 21840 KB Output is correct
14 Correct 15 ms 22008 KB Output is correct
15 Correct 15 ms 21840 KB Output is correct
16 Correct 14 ms 22020 KB Output is correct
17 Correct 13 ms 21840 KB Output is correct
18 Correct 13 ms 22000 KB Output is correct
19 Runtime error 44 ms 47688 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -