Submission #1043850

# Submission time Handle Problem Language Result Execution time Memory
1043850 2024-08-05T01:21:30 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
644 ms 160848 KB
#include <bits/stdc++.h>
#define file "main"
#define maxn (int) 1e6 + 5
#define pii pair<int, int>
#define ll long long
#define gb(i, j) ((i >> j) & 1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

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(file".inp", "r")) {
        freopen(file".inp", "r", stdin);
//        freopen(file".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}

int n, Q, ans[maxn];
int a[maxn], pre[maxn];
int L[maxn][20], Log[maxn];
struct dl { int f, s, k, id; } qr[maxn];
vector<int> o[maxn];

struct SEGMT {
    int st[4 * maxn];

    void build(int id = 1, int l = 1, int r = n) {
        if(l == r) return st[id] = pre[l] != 0 ? a[l] + a[ pre[l] ] : 0, void();
        int mid = (l + r) >> 1;
        build(_left), build(_right);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
    void update(int i, int id = 1, int l = 1, int r = n) {
        if(i < l || r < i) return ;
        if(l == r) return st[id] = 0, void();
        int mid = (l + r) >> 1;
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
    int get(int u, int v, int id = 1, int l = 1, int r = n) {
        if(v < l || r < u) return 0;
        if(u <= l && r <= v) return st[id];
        int mid = (l + r) >> 1;
        return max( get(u, v, _left), get(u, v, _right) );
    }
} ST;

int get(int i, int j) {
    int kc = Log[j - i + 1];
    return max( L[i][kc], L[j - (1 << kc) + 1][kc] );
}
void solve() {
    cin >> n >> Q ;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i], L[i][0] = a[i], Log[i] = __lg(i);
    }

    for(int i = 1; i <= Log[n]; i ++) {
        for(int j = 1; j + (1 << i) - 1 <= n; j ++) {
            L[j][i] = max(L[j][i - 1], L[j + (1 << (i - 1))][i - 1]);
        }
    }

    for(int i = 1; i <= n; i ++) {
        int l = 1, r = i;
        while(l <= r) {
            int mid = (l + r) >> 1;
            if( get(mid, i) > a[i] ) l = mid + 1;
            else r = mid - 1;
        }
        pre[i] = r;
        o[r].push_back(i);
    }

    ST.build();
    for(int i = 1; i <= Q; i ++) cin >> qr[i].f >> qr[i].s >> qr[i].k, qr[i].id = i;

    sort(qr + 1, qr + Q + 1, [](dl x, dl y) {
        return x.f < y.f;
    });

    int j = 1;
    for(int i = 1; i <= Q; i ++) {
        int l = qr[i].f, r = qr[i].s, k = qr[i].k, id = qr[i].id;
        while(j < l) {
            for(int pos : o[j]) {
                ST.update(pos);
            }
            j ++;
        }
        ans[id] = ST.get(l, r) <= k;
    }
    for(int i = 1; i <= Q; i ++) cout << ans[i] << '\n';
}

int main()
{
    iof();

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

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

    return 0;
}

Compilation message

sortbooks.cpp: In member function 'void SEGMT::update(int, int, int, int)':
sortbooks.cpp:44:13: warning: unused variable 'mid' [-Wunused-variable]
   44 |         int mid = (l + r) >> 1;
      |             ^~~
sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35164 KB Output is correct
2 Correct 4 ms 35304 KB Output is correct
3 Incorrect 4 ms 35296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35164 KB Output is correct
2 Correct 4 ms 35304 KB Output is correct
3 Incorrect 4 ms 35296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 644 ms 160848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 49488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35164 KB Output is correct
2 Correct 4 ms 35304 KB Output is correct
3 Incorrect 4 ms 35296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35164 KB Output is correct
2 Correct 4 ms 35304 KB Output is correct
3 Incorrect 4 ms 35296 KB Output isn't correct
4 Halted 0 ms 0 KB -