답안 #1043851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043851 2024-08-05T01:24:39 Z Yang8on Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
658 ms 160852 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];

int get(int i, int j) {
    int kc = Log[j - i + 1];
    return max( L[i][kc], L[j - (1 << kc) + 1][kc] );
}

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;

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:49:13: warning: unused variable 'mid' [-Wunused-variable]
   49 |         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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35160 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Incorrect 4 ms 35164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35160 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Incorrect 4 ms 35164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 658 ms 160852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 49440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35160 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Incorrect 4 ms 35164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35160 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Incorrect 4 ms 35164 KB Output isn't correct
4 Halted 0 ms 0 KB -