Submission #1040324

# Submission time Handle Problem Language Result Execution time Memory
1040324 2024-08-01T01:11:46 Z Yang8on Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
77 / 100
2076 ms 262148 KB
#include <bits/stdc++.h>
#define Y8o "Hedgehog Daniyar and Algorithms"
#define maxn (int) 1e6 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}


int n, Q, a[maxn];

vector<int> cur[4 * maxn];
int st[4 * maxn];

int cb(int id, int id2) {
    int mx = cur[id].back();
    int pos = lower_bound(all(cur[id2]), mx) - cur[id2].begin();
    if(pos != 0) {
        pos --;
        return mx + cur[id2][pos];
    }
    return 0;
}

struct SEGMENTREE {
    void build(int id = 1, int l = 1, int r = n) {
        if(l == r) {
            st[id] = 0, cur[id].clear();
            cur[id].push_back(a[l]);
            return ;
        }
        int mid = (l + r) >> 1;
        build(_left), build(_right);

        st[id] = max({ st[id * 2], st[id * 2 + 1], cb(id * 2, id * 2 + 1) });
        cur[id].clear(), merge(all(cur[id * 2]), all(cur[id * 2 + 1]), back_inserter(cur[id]));
    }

    void get(int u, int v, vector<int>& res, int id = 1, int l = 1, int r = n) {
        if(v < l || r < u) return ;
        if(u <= l && r <= v) return res.push_back(id), void();
        int mid = (l + r) >> 1;
        get(u, v, res, _left), get(u, v, res, _right);
    }
} ST;

void solve()
{
    cin >> n >> Q;
    for(int i = 1; i <= n; i ++) cin >> a[i];
//    n = GetRandom(5, 5), Q=  GetRandom(10, 10);
//    cout << n << ' ' << Q << '\n';
//    for(int i = 1; i <= n; i ++) a[i] = GetRandom(0, 10), cout << a[i] << ' ';
//    cout << '\n';

    ST.build();

    for(int i = 1; i <= Q; i ++) {
        int l, r, k, ans = 0; cin >> l >> r >> k;
//        int ans = 0, l = GetRandom(1, n), r = GetRandom(1, n), k = GetRandom(0, 20);
//        if(l > r) swap(l, r);
//        cout << l << ' ' << r << ' ' << k << '\n';

        vector<int> res;
        ST.get(l, r, res);

        if(res.size()) {
            int pre = 0;
            for(int id : res) {
                ans = max(ans, st[id]);
                if(pre) ans = max(ans, cb(pre, id));
                if(pre == 0 || cur[pre].back() < cur[id].back()) pre = id;
            }
        }
        cout << (ans <= k) << '\n';
//        cout << "ANS :" << ' ' << (ans <= k) << ' ';

//        ans = 0;
//        for(int it1 = l; it1 <= r; it1 ++) {
//            for(int it2 = l; it2 < it1; it2 ++) {
//                if(a[it1] < a[it2]) ans = max(ans, a[it2] + a[it1]);
//            }
//        }
//        cout << (ans <= k) << '\n';
    }

}


int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94288 KB Output is correct
2 Correct 32 ms 94296 KB Output is correct
3 Correct 33 ms 94296 KB Output is correct
4 Correct 35 ms 94308 KB Output is correct
5 Correct 31 ms 94288 KB Output is correct
6 Correct 33 ms 94300 KB Output is correct
7 Correct 33 ms 94288 KB Output is correct
8 Correct 32 ms 94288 KB Output is correct
9 Correct 31 ms 94288 KB Output is correct
10 Correct 46 ms 94292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94288 KB Output is correct
2 Correct 32 ms 94296 KB Output is correct
3 Correct 33 ms 94296 KB Output is correct
4 Correct 35 ms 94308 KB Output is correct
5 Correct 31 ms 94288 KB Output is correct
6 Correct 33 ms 94300 KB Output is correct
7 Correct 33 ms 94288 KB Output is correct
8 Correct 32 ms 94288 KB Output is correct
9 Correct 31 ms 94288 KB Output is correct
10 Correct 46 ms 94292 KB Output is correct
11 Correct 32 ms 94548 KB Output is correct
12 Correct 53 ms 95056 KB Output is correct
13 Correct 44 ms 95060 KB Output is correct
14 Correct 39 ms 95068 KB Output is correct
15 Correct 44 ms 95060 KB Output is correct
16 Correct 37 ms 95228 KB Output is correct
17 Correct 45 ms 94824 KB Output is correct
18 Correct 37 ms 95052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1978 ms 262144 KB Output is correct
2 Correct 2076 ms 262144 KB Output is correct
3 Correct 2019 ms 262144 KB Output is correct
4 Correct 2019 ms 262144 KB Output is correct
5 Correct 1848 ms 262144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 111172 KB Output is correct
2 Correct 169 ms 111072 KB Output is correct
3 Correct 164 ms 111088 KB Output is correct
4 Correct 152 ms 111048 KB Output is correct
5 Correct 161 ms 111000 KB Output is correct
6 Correct 136 ms 111084 KB Output is correct
7 Correct 122 ms 111064 KB Output is correct
8 Correct 132 ms 110824 KB Output is correct
9 Correct 69 ms 95916 KB Output is correct
10 Correct 121 ms 110712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94288 KB Output is correct
2 Correct 32 ms 94296 KB Output is correct
3 Correct 33 ms 94296 KB Output is correct
4 Correct 35 ms 94308 KB Output is correct
5 Correct 31 ms 94288 KB Output is correct
6 Correct 33 ms 94300 KB Output is correct
7 Correct 33 ms 94288 KB Output is correct
8 Correct 32 ms 94288 KB Output is correct
9 Correct 31 ms 94288 KB Output is correct
10 Correct 46 ms 94292 KB Output is correct
11 Correct 32 ms 94548 KB Output is correct
12 Correct 53 ms 95056 KB Output is correct
13 Correct 44 ms 95060 KB Output is correct
14 Correct 39 ms 95068 KB Output is correct
15 Correct 44 ms 95060 KB Output is correct
16 Correct 37 ms 95228 KB Output is correct
17 Correct 45 ms 94824 KB Output is correct
18 Correct 37 ms 95052 KB Output is correct
19 Correct 369 ms 131392 KB Output is correct
20 Correct 335 ms 131268 KB Output is correct
21 Correct 271 ms 131272 KB Output is correct
22 Correct 266 ms 131272 KB Output is correct
23 Correct 272 ms 131280 KB Output is correct
24 Correct 230 ms 131028 KB Output is correct
25 Correct 233 ms 131092 KB Output is correct
26 Correct 263 ms 131640 KB Output is correct
27 Correct 258 ms 131276 KB Output is correct
28 Correct 269 ms 131308 KB Output is correct
29 Correct 262 ms 131252 KB Output is correct
30 Correct 266 ms 131276 KB Output is correct
31 Correct 286 ms 131360 KB Output is correct
32 Correct 285 ms 131276 KB Output is correct
33 Correct 311 ms 131272 KB Output is correct
34 Correct 219 ms 131016 KB Output is correct
35 Correct 228 ms 131016 KB Output is correct
36 Correct 224 ms 130800 KB Output is correct
37 Correct 225 ms 130756 KB Output is correct
38 Correct 222 ms 131016 KB Output is correct
39 Correct 238 ms 129968 KB Output is correct
40 Correct 164 ms 116432 KB Output is correct
41 Correct 227 ms 129480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94288 KB Output is correct
2 Correct 32 ms 94296 KB Output is correct
3 Correct 33 ms 94296 KB Output is correct
4 Correct 35 ms 94308 KB Output is correct
5 Correct 31 ms 94288 KB Output is correct
6 Correct 33 ms 94300 KB Output is correct
7 Correct 33 ms 94288 KB Output is correct
8 Correct 32 ms 94288 KB Output is correct
9 Correct 31 ms 94288 KB Output is correct
10 Correct 46 ms 94292 KB Output is correct
11 Correct 32 ms 94548 KB Output is correct
12 Correct 53 ms 95056 KB Output is correct
13 Correct 44 ms 95060 KB Output is correct
14 Correct 39 ms 95068 KB Output is correct
15 Correct 44 ms 95060 KB Output is correct
16 Correct 37 ms 95228 KB Output is correct
17 Correct 45 ms 94824 KB Output is correct
18 Correct 37 ms 95052 KB Output is correct
19 Correct 1978 ms 262144 KB Output is correct
20 Correct 2076 ms 262144 KB Output is correct
21 Correct 2019 ms 262144 KB Output is correct
22 Correct 2019 ms 262144 KB Output is correct
23 Correct 1848 ms 262144 KB Output is correct
24 Correct 177 ms 111172 KB Output is correct
25 Correct 169 ms 111072 KB Output is correct
26 Correct 164 ms 111088 KB Output is correct
27 Correct 152 ms 111048 KB Output is correct
28 Correct 161 ms 111000 KB Output is correct
29 Correct 136 ms 111084 KB Output is correct
30 Correct 122 ms 111064 KB Output is correct
31 Correct 132 ms 110824 KB Output is correct
32 Correct 69 ms 95916 KB Output is correct
33 Correct 121 ms 110712 KB Output is correct
34 Correct 369 ms 131392 KB Output is correct
35 Correct 335 ms 131268 KB Output is correct
36 Correct 271 ms 131272 KB Output is correct
37 Correct 266 ms 131272 KB Output is correct
38 Correct 272 ms 131280 KB Output is correct
39 Correct 230 ms 131028 KB Output is correct
40 Correct 233 ms 131092 KB Output is correct
41 Correct 263 ms 131640 KB Output is correct
42 Correct 258 ms 131276 KB Output is correct
43 Correct 269 ms 131308 KB Output is correct
44 Correct 262 ms 131252 KB Output is correct
45 Correct 266 ms 131276 KB Output is correct
46 Correct 286 ms 131360 KB Output is correct
47 Correct 285 ms 131276 KB Output is correct
48 Correct 311 ms 131272 KB Output is correct
49 Correct 219 ms 131016 KB Output is correct
50 Correct 228 ms 131016 KB Output is correct
51 Correct 224 ms 130800 KB Output is correct
52 Correct 225 ms 130756 KB Output is correct
53 Correct 222 ms 131016 KB Output is correct
54 Correct 238 ms 129968 KB Output is correct
55 Correct 164 ms 116432 KB Output is correct
56 Correct 227 ms 129480 KB Output is correct
57 Correct 1932 ms 262144 KB Output is correct
58 Runtime error 1962 ms 262148 KB Memory limit exceeded
59 Halted 0 ms 0 KB -