답안 #947503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947503 2024-03-16T10:05:59 Z dilanyan Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
13 / 100
2155 ms 75812 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------KarginDefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
 
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1000000007;
const ll inf = 1e9 + 10;
 
//-------------------KarginCode------------------------\\ 
 
const int N = 1000005;
int w[N];

int n, m;

struct query {
    int l, r, k;
};

query q[N];

struct segtree_sort {

    int size = 1;

    struct node {
        bool sorted = true, valid = false;
        int l = 0, r = 0;
    };

    node z;

    vector<node> tree;

    void init() {
        while (size < n) size <<= 1;
        tree.resize(2 * size);
        build(0, 0, size);
    }

    node merge(node b, node c) {
        node a;
        if (!b.valid && !c.valid) {
            a.valid = false;
            return a;
        }
        if (!c.valid) a = b;
        else {
            a.valid = true;
            if (!b.sorted || !c.sorted) {
                a.sorted = false;
                return a;
            }
            if (b.r <= c.l) { 
                a.sorted = true;
                a.l = b.l, a.r = c.r;
            }
            else a.sorted = false;
        }
        return a;
    }

    void build(int x, int lx, int rx) {
        if (rx - lx == 1) {
            tree[x].valid = false;
            if (lx < n) {
                tree[x].valid = tree[x].sorted = true;
                tree[x].l = tree[x].r = w[lx];
            }
            return;
        }
        int m = (lx + rx) / 2;
        build(2 * x + 1, lx, m);
        build(2 * x + 2, m, rx);
        tree[x] = merge(tree[2 * x + 1], tree[2 * x + 2]);
    }

    node get(int l, int r, int x, int lx, int rx) {
        if (lx >= r || rx <= l) return z;
        if (lx >= l && rx <= r) return tree[x];
        int m = (lx + rx) / 2;
        node getl = get(l, r, 2 * x + 1, lx, m),
            getr = get(l, r, 2 * x + 2, m, rx);
        node get0 = merge(getl, getr);
        return get0;
    }

    bool get(int l, int r) {
        return get(l, r, 0, 0, size).sorted;
    }

};

void KarginSolve() {
    cin >> n >> m;
    int mn = inf;
    for (int i = 0;i < n;i++) cin >> w[i], mn = min(mn, w[i]);
    bool case3 = true;
    for (int i = 0;i < m;i++) {
        cin >> q[i].l >> q[i].r >> q[i].k;
        q[i].l--;
        if (q[i].k >= mn) case3 = false;
    }
    if (case3) {
        segtree_sort st;
        st.init();
        for (int i = 0;i < m;i++) {
            if (st.get(q[i].l, q[i].r)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}
 
int main() {
    //Usaco
    Kargin;
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message

sortbooks.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
sortbooks.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------KarginDefines--------------------\\
      | ^
sortbooks.cpp:22:1: warning: multi-line comment [-Wcomment]
   22 | //-------------------KarginConstants------------------\\
      | ^
sortbooks.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginCode------------------------\\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2155 ms 59184 KB Output is correct
2 Correct 2111 ms 75812 KB Output is correct
3 Correct 2103 ms 75404 KB Output is correct
4 Correct 2063 ms 75628 KB Output is correct
5 Correct 2012 ms 75584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 6236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -