답안 #337758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337758 2020-12-21T13:54:26 Z BeanZ Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1948 ms 125124 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 50;
long long mod = 1e9 + 7;
const int lim = 700;
const int lg = 18;
const int base = 311;
const long double eps = 1e-6;
struct viet{
    ll l, k, id;
};
ll st[N * 4], a[N], ans[N];
void upd(ll k, ll l, ll r, ll x, ll v){
    if (x > r || x < l) return;
    if (l == r){
        st[k] = max(st[k], v);
        return;
    }
    ll mid = (l + r) >> 1;
    upd(k << 1, l, mid, x, v);
    upd(k << 1 | 1, mid + 1, r, x, v);
    st[k] = max(st[k << 1], st[k << 1 | 1]);
}
ll get(ll k, ll l, ll r, ll x, ll y){
    if (x > r || y < l) return 0;
    if (x <= l && y >= r) return st[k];
    ll mid = (l + r) >> 1;
    return max(get(k << 1, l, mid, x, y), get(k << 1 | 1, mid + 1, r, x, y));
}
vector<viet> Q[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        ll l, r, k;
        cin >> l >> r >> k;
        Q[r].push_back({l, k, i});
    }
    vector<ll> st;
    for (int i = 1; i <= n; i++){
        while (st.size()){
            if (a[st.back()] <= a[i]){
                st.pop_back();
            } else break;
        }
        if (st.size()) upd(1, 1, n, st.back(), a[st.back()] + a[i]);
        st.push_back(i);
        for (auto j : Q[i]){
            ll val = get(1, 1, n, j.l, i);
            if (val > j.k) ans[j.id] = 0;
            else ans[j.id] = 1;
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << endl;
}
/*
Ans:

Out:
*/

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   38 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 15 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 15 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 18 ms 24172 KB Output is correct
12 Correct 19 ms 24300 KB Output is correct
13 Correct 19 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 21 ms 24428 KB Output is correct
16 Correct 20 ms 24300 KB Output is correct
17 Correct 21 ms 24172 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1940 ms 122348 KB Output is correct
2 Correct 1917 ms 123372 KB Output is correct
3 Correct 1929 ms 123500 KB Output is correct
4 Correct 1939 ms 123392 KB Output is correct
5 Correct 1437 ms 107244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 32876 KB Output is correct
2 Correct 135 ms 33260 KB Output is correct
3 Correct 118 ms 30956 KB Output is correct
4 Correct 115 ms 30956 KB Output is correct
5 Correct 114 ms 30828 KB Output is correct
6 Correct 95 ms 30828 KB Output is correct
7 Correct 93 ms 30828 KB Output is correct
8 Correct 113 ms 30240 KB Output is correct
9 Correct 60 ms 29108 KB Output is correct
10 Correct 110 ms 30240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 15 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 18 ms 24172 KB Output is correct
12 Correct 19 ms 24300 KB Output is correct
13 Correct 19 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 21 ms 24428 KB Output is correct
16 Correct 20 ms 24300 KB Output is correct
17 Correct 21 ms 24172 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 329 ms 44652 KB Output is correct
20 Correct 330 ms 44652 KB Output is correct
21 Correct 280 ms 45048 KB Output is correct
22 Correct 284 ms 45164 KB Output is correct
23 Correct 289 ms 45164 KB Output is correct
24 Correct 216 ms 40940 KB Output is correct
25 Correct 223 ms 40940 KB Output is correct
26 Correct 255 ms 40812 KB Output is correct
27 Correct 245 ms 40684 KB Output is correct
28 Correct 254 ms 40684 KB Output is correct
29 Correct 261 ms 40556 KB Output is correct
30 Correct 264 ms 40556 KB Output is correct
31 Correct 265 ms 40560 KB Output is correct
32 Correct 261 ms 40684 KB Output is correct
33 Correct 257 ms 40556 KB Output is correct
34 Correct 199 ms 40300 KB Output is correct
35 Correct 205 ms 40300 KB Output is correct
36 Correct 195 ms 40172 KB Output is correct
37 Correct 201 ms 40172 KB Output is correct
38 Correct 198 ms 40300 KB Output is correct
39 Correct 237 ms 40096 KB Output is correct
40 Correct 179 ms 37020 KB Output is correct
41 Correct 235 ms 38172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 15 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 18 ms 24172 KB Output is correct
12 Correct 19 ms 24300 KB Output is correct
13 Correct 19 ms 24300 KB Output is correct
14 Correct 21 ms 24428 KB Output is correct
15 Correct 21 ms 24428 KB Output is correct
16 Correct 20 ms 24300 KB Output is correct
17 Correct 21 ms 24172 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 1940 ms 122348 KB Output is correct
20 Correct 1917 ms 123372 KB Output is correct
21 Correct 1929 ms 123500 KB Output is correct
22 Correct 1939 ms 123392 KB Output is correct
23 Correct 1437 ms 107244 KB Output is correct
24 Correct 147 ms 32876 KB Output is correct
25 Correct 135 ms 33260 KB Output is correct
26 Correct 118 ms 30956 KB Output is correct
27 Correct 115 ms 30956 KB Output is correct
28 Correct 114 ms 30828 KB Output is correct
29 Correct 95 ms 30828 KB Output is correct
30 Correct 93 ms 30828 KB Output is correct
31 Correct 113 ms 30240 KB Output is correct
32 Correct 60 ms 29108 KB Output is correct
33 Correct 110 ms 30240 KB Output is correct
34 Correct 329 ms 44652 KB Output is correct
35 Correct 330 ms 44652 KB Output is correct
36 Correct 280 ms 45048 KB Output is correct
37 Correct 284 ms 45164 KB Output is correct
38 Correct 289 ms 45164 KB Output is correct
39 Correct 216 ms 40940 KB Output is correct
40 Correct 223 ms 40940 KB Output is correct
41 Correct 255 ms 40812 KB Output is correct
42 Correct 245 ms 40684 KB Output is correct
43 Correct 254 ms 40684 KB Output is correct
44 Correct 261 ms 40556 KB Output is correct
45 Correct 264 ms 40556 KB Output is correct
46 Correct 265 ms 40560 KB Output is correct
47 Correct 261 ms 40684 KB Output is correct
48 Correct 257 ms 40556 KB Output is correct
49 Correct 199 ms 40300 KB Output is correct
50 Correct 205 ms 40300 KB Output is correct
51 Correct 195 ms 40172 KB Output is correct
52 Correct 201 ms 40172 KB Output is correct
53 Correct 198 ms 40300 KB Output is correct
54 Correct 237 ms 40096 KB Output is correct
55 Correct 179 ms 37020 KB Output is correct
56 Correct 235 ms 38172 KB Output is correct
57 Correct 1924 ms 124196 KB Output is correct
58 Correct 1948 ms 124184 KB Output is correct
59 Correct 1861 ms 125124 KB Output is correct
60 Correct 1845 ms 125116 KB Output is correct
61 Correct 1868 ms 124972 KB Output is correct
62 Correct 1852 ms 125036 KB Output is correct
63 Correct 1137 ms 109012 KB Output is correct
64 Correct 1114 ms 108524 KB Output is correct
65 Correct 1407 ms 108780 KB Output is correct
66 Correct 1398 ms 108616 KB Output is correct
67 Correct 1418 ms 108780 KB Output is correct
68 Correct 1432 ms 107976 KB Output is correct
69 Correct 1425 ms 107884 KB Output is correct
70 Correct 1469 ms 107988 KB Output is correct
71 Correct 1453 ms 108244 KB Output is correct
72 Correct 1448 ms 107988 KB Output is correct
73 Correct 977 ms 102508 KB Output is correct
74 Correct 998 ms 103660 KB Output is correct
75 Correct 979 ms 102856 KB Output is correct
76 Correct 980 ms 102892 KB Output is correct
77 Correct 982 ms 102380 KB Output is correct
78 Correct 1312 ms 104848 KB Output is correct
79 Correct 904 ms 88448 KB Output is correct
80 Correct 1325 ms 95856 KB Output is correct