답안 #673273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673273 2022-12-20T04:56:43 Z Alihan_8 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1323 ms 148556 KB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
const int N = 1e6+1, inf = 1e16+1;
struct SegTree{
    vector <int> T;
    void re_size(int n){
        T.resize(n*4+1);
    }
    void upd(int v, int l, int r, int pos, int val){
        if ( l == r ){
            T[v] = val;
            return;
        }
        int md = (l+r)>>1;
        if ( pos <= md ) upd(v*2, l, md, pos, val);
        else upd(v*2+1, md+1, r, pos, val);
        T[v] = max(T[v*2], T[v*2+1]);
    }
    int get(int v, int l, int r, int tl, int tr){
        if ( r < tl or l > tr ) return 0;
        if ( tl <= l and tr >= r ) return T[v];
        int md = (l+r)>>1;
        return max(get(v*2, l, md, tl, tr), get(v*2+1, md+1, r, tl, tr));
    }
} Tree;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m; cin >> n >> m;
    Tree.re_size(N);
    vector <int> p(n);
    for ( auto &i: p ) cin >> i;
    struct query{
        int l, r, k;
    };
    vector <query> q(m);
    vector <int> g[n+1], res(m);
    for ( auto &[l, r, k]: q ) cin >> l >> r >> k, l--, r--;
    for ( int i = 0; i < m; i++ ){
        g[q[i].r].pb(i);
    }
    stack <int> stk;
    for ( int i = 0; i < n; i++ ){
        while ( !stk.empty() and p[stk.top()] <= p[i] ) stk.pop();
        if ( !stk.empty() ){
            Tree.upd(1, 0, n-1, stk.top(), p[stk.top()]+p[i]);
        }
        for ( auto cur: g[i] ){
            auto [l, r, k] = q[cur];
            res[cur] = Tree.get(1, 0, n-1, l, r) <= k;
        }
        stk.push(i);
    }
    for ( auto i: res ) cout << i << ln;

    cout << '\n';
}

Compilation message

sortbooks.cpp: In function 'void IO(std::string)':
sortbooks.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 31604 KB Output is correct
2 Correct 13 ms 31512 KB Output is correct
3 Correct 14 ms 31568 KB Output is correct
4 Correct 15 ms 31524 KB Output is correct
5 Correct 14 ms 31668 KB Output is correct
6 Correct 13 ms 31572 KB Output is correct
7 Correct 13 ms 31572 KB Output is correct
8 Correct 14 ms 31628 KB Output is correct
9 Correct 13 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 31604 KB Output is correct
2 Correct 13 ms 31512 KB Output is correct
3 Correct 14 ms 31568 KB Output is correct
4 Correct 15 ms 31524 KB Output is correct
5 Correct 14 ms 31668 KB Output is correct
6 Correct 13 ms 31572 KB Output is correct
7 Correct 13 ms 31572 KB Output is correct
8 Correct 14 ms 31628 KB Output is correct
9 Correct 13 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 16 ms 31920 KB Output is correct
13 Correct 16 ms 32024 KB Output is correct
14 Correct 18 ms 32068 KB Output is correct
15 Correct 19 ms 32092 KB Output is correct
16 Correct 16 ms 32036 KB Output is correct
17 Correct 16 ms 32084 KB Output is correct
18 Correct 16 ms 32084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1252 ms 116016 KB Output is correct
2 Correct 1252 ms 116388 KB Output is correct
3 Correct 1254 ms 115980 KB Output is correct
4 Correct 1250 ms 116120 KB Output is correct
5 Correct 1127 ms 116012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 39880 KB Output is correct
2 Correct 88 ms 41360 KB Output is correct
3 Correct 88 ms 41708 KB Output is correct
4 Correct 97 ms 41860 KB Output is correct
5 Correct 83 ms 41908 KB Output is correct
6 Correct 71 ms 40964 KB Output is correct
7 Correct 72 ms 40956 KB Output is correct
8 Correct 86 ms 41488 KB Output is correct
9 Correct 48 ms 37188 KB Output is correct
10 Correct 84 ms 41488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 31604 KB Output is correct
2 Correct 13 ms 31512 KB Output is correct
3 Correct 14 ms 31568 KB Output is correct
4 Correct 15 ms 31524 KB Output is correct
5 Correct 14 ms 31668 KB Output is correct
6 Correct 13 ms 31572 KB Output is correct
7 Correct 13 ms 31572 KB Output is correct
8 Correct 14 ms 31628 KB Output is correct
9 Correct 13 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 16 ms 31920 KB Output is correct
13 Correct 16 ms 32024 KB Output is correct
14 Correct 18 ms 32068 KB Output is correct
15 Correct 19 ms 32092 KB Output is correct
16 Correct 16 ms 32036 KB Output is correct
17 Correct 16 ms 32084 KB Output is correct
18 Correct 16 ms 32084 KB Output is correct
19 Correct 221 ms 54820 KB Output is correct
20 Correct 236 ms 54860 KB Output is correct
21 Correct 186 ms 53528 KB Output is correct
22 Correct 182 ms 53516 KB Output is correct
23 Correct 188 ms 53592 KB Output is correct
24 Correct 157 ms 53372 KB Output is correct
25 Correct 153 ms 53288 KB Output is correct
26 Correct 174 ms 53968 KB Output is correct
27 Correct 175 ms 54040 KB Output is correct
28 Correct 183 ms 54120 KB Output is correct
29 Correct 204 ms 54808 KB Output is correct
30 Correct 208 ms 54860 KB Output is correct
31 Correct 191 ms 54816 KB Output is correct
32 Correct 188 ms 54816 KB Output is correct
33 Correct 190 ms 54788 KB Output is correct
34 Correct 151 ms 52940 KB Output is correct
35 Correct 142 ms 52912 KB Output is correct
36 Correct 147 ms 52760 KB Output is correct
37 Correct 141 ms 52808 KB Output is correct
38 Correct 144 ms 53004 KB Output is correct
39 Correct 172 ms 53056 KB Output is correct
40 Correct 132 ms 49856 KB Output is correct
41 Correct 170 ms 52668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 31604 KB Output is correct
2 Correct 13 ms 31512 KB Output is correct
3 Correct 14 ms 31568 KB Output is correct
4 Correct 15 ms 31524 KB Output is correct
5 Correct 14 ms 31668 KB Output is correct
6 Correct 13 ms 31572 KB Output is correct
7 Correct 13 ms 31572 KB Output is correct
8 Correct 14 ms 31628 KB Output is correct
9 Correct 13 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 16 ms 31920 KB Output is correct
13 Correct 16 ms 32024 KB Output is correct
14 Correct 18 ms 32068 KB Output is correct
15 Correct 19 ms 32092 KB Output is correct
16 Correct 16 ms 32036 KB Output is correct
17 Correct 16 ms 32084 KB Output is correct
18 Correct 16 ms 32084 KB Output is correct
19 Correct 1252 ms 116016 KB Output is correct
20 Correct 1252 ms 116388 KB Output is correct
21 Correct 1254 ms 115980 KB Output is correct
22 Correct 1250 ms 116120 KB Output is correct
23 Correct 1127 ms 116012 KB Output is correct
24 Correct 98 ms 39880 KB Output is correct
25 Correct 88 ms 41360 KB Output is correct
26 Correct 88 ms 41708 KB Output is correct
27 Correct 97 ms 41860 KB Output is correct
28 Correct 83 ms 41908 KB Output is correct
29 Correct 71 ms 40964 KB Output is correct
30 Correct 72 ms 40956 KB Output is correct
31 Correct 86 ms 41488 KB Output is correct
32 Correct 48 ms 37188 KB Output is correct
33 Correct 84 ms 41488 KB Output is correct
34 Correct 221 ms 54820 KB Output is correct
35 Correct 236 ms 54860 KB Output is correct
36 Correct 186 ms 53528 KB Output is correct
37 Correct 182 ms 53516 KB Output is correct
38 Correct 188 ms 53592 KB Output is correct
39 Correct 157 ms 53372 KB Output is correct
40 Correct 153 ms 53288 KB Output is correct
41 Correct 174 ms 53968 KB Output is correct
42 Correct 175 ms 54040 KB Output is correct
43 Correct 183 ms 54120 KB Output is correct
44 Correct 204 ms 54808 KB Output is correct
45 Correct 208 ms 54860 KB Output is correct
46 Correct 191 ms 54816 KB Output is correct
47 Correct 188 ms 54816 KB Output is correct
48 Correct 190 ms 54788 KB Output is correct
49 Correct 151 ms 52940 KB Output is correct
50 Correct 142 ms 52912 KB Output is correct
51 Correct 147 ms 52760 KB Output is correct
52 Correct 141 ms 52808 KB Output is correct
53 Correct 144 ms 53004 KB Output is correct
54 Correct 172 ms 53056 KB Output is correct
55 Correct 132 ms 49856 KB Output is correct
56 Correct 170 ms 52668 KB Output is correct
57 Correct 1323 ms 148420 KB Output is correct
58 Correct 1263 ms 148400 KB Output is correct
59 Correct 1159 ms 145808 KB Output is correct
60 Correct 1153 ms 145732 KB Output is correct
61 Correct 1150 ms 145740 KB Output is correct
62 Correct 1144 ms 145676 KB Output is correct
63 Correct 766 ms 140188 KB Output is correct
64 Correct 775 ms 140364 KB Output is correct
65 Correct 1018 ms 145432 KB Output is correct
66 Correct 1010 ms 145428 KB Output is correct
67 Correct 1020 ms 145680 KB Output is correct
68 Correct 1127 ms 148488 KB Output is correct
69 Correct 1114 ms 148556 KB Output is correct
70 Correct 1151 ms 148036 KB Output is correct
71 Correct 1138 ms 147916 KB Output is correct
72 Correct 1156 ms 147896 KB Output is correct
73 Correct 786 ms 137160 KB Output is correct
74 Correct 783 ms 137880 KB Output is correct
75 Correct 743 ms 137156 KB Output is correct
76 Correct 730 ms 137160 KB Output is correct
77 Correct 749 ms 136876 KB Output is correct
78 Correct 995 ms 140596 KB Output is correct
79 Correct 716 ms 118452 KB Output is correct
80 Correct 954 ms 137972 KB Output is correct