답안 #1097289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097289 2024-10-06T16:22:11 Z TrinhKhanhDung Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
572 ms 70548 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(998244353)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 1e6 + 10;

struct fen{
    vector<int> tree;
    int n;

    fen(int _n = 0){
        n = _n;
        tree.resize(n + 3, 0);
    }

    void upd(int p, int c){
        for(; p <= n; p += p & -p) tree[p] += c;
    }

    int get(int p){
        int ans = 0;
        for(; p > 0; p -= p & -p) ans += tree[p];
        return ans;
    }

    int get(int l, int r){
        return get(r) - get(l - 1);
    }
};

const int maxN = 1e6 + 10;

int N, Q;
int a[maxN], ans[maxN];
vector<array<int, 2>> arr;
vector<array<int, 4>> que;

void solve(){
    cin >> N >> Q;
    for(int i = 1; i <= N; i++){
        int x; cin >> x;
        a[i] = x;
        arr.push_back({x, i});
    }
    for(int i = 1; i <= Q; i++){
        int l, r, k; cin >> l >> r >> k;
        que.push_back({k, l, r, i});
    }
    sort(ALL(arr));
    sort(ALL(que));

    fen bit(N - 1);

    int j = N - 1;
    for(int i = Q - 1; i >= 0; i--){
        while(j >= 0 && arr[j][0] > que[i][0]){
            if(arr[j][1] < N && a[arr[j][1] + 1] < a[arr[j][1]]){
                bit.upd(arr[j][1], 1);
            }
            j--;
        }
        int l = que[i][1], r = que[i][2], id = que[i][3];
        ans[id] = (bit.get(l, r - 1) == 0);
    }

    for(int i = 1; i <= Q; i++) cout << ans[i] << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("boxes.inp","r",stdin);
//     freopen("boxes.out","w",stdout);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 69300 KB Output is correct
2 Correct 572 ms 70416 KB Output is correct
3 Correct 568 ms 70180 KB Output is correct
4 Correct 554 ms 70548 KB Output is correct
5 Correct 542 ms 70420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 6216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -