Submission #1040321

# Submission time Handle Problem Language Result Execution time Memory
1040321 2024-08-01T01:04:27 Z Yang8on Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1938 ms 262144 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];

    ST.build();

    for(int i = 1; i <= Q; i ++) {
        int l, r, k, ans = 0; cin >> l >> r >> k;
        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(st[pre] < st[id]) pre = id;
            }
        }
        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 35 ms 94292 KB Output is correct
2 Correct 32 ms 94292 KB Output is correct
3 Incorrect 35 ms 94392 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 94292 KB Output is correct
2 Correct 32 ms 94292 KB Output is correct
3 Incorrect 35 ms 94392 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1938 ms 262144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 142 ms 111052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 94292 KB Output is correct
2 Correct 32 ms 94292 KB Output is correct
3 Incorrect 35 ms 94392 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 94292 KB Output is correct
2 Correct 32 ms 94292 KB Output is correct
3 Incorrect 35 ms 94392 KB Output isn't correct
4 Halted 0 ms 0 KB -