답안 #655043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655043 2022-11-02T19:34:41 Z stevancv Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
1450 ms 30960 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
struct node {
    int mx, mn, ans;
}st[4 * N];
int arr[N];
node Merge(node a, node b) {
    node c;
    c.ans = max(a.ans, b.ans);
    if (a.mx > b.mn) smax(c.ans, a.mx + b.mn);
    c.mx = max(a.mx, b.mx);
    c.mn = min(a.mn, b.mn);
    return c;
}
void Init(int node, int l, int r) {
    if (l == r) {
        st[node] = {arr[l], arr[l], 0};
        return;
    }
    int mid = l + r >> 1;
    Init(2 * node, l, mid);
    Init(2 * node + 1, mid + 1, r);
    st[node] = Merge(st[2 * node], st[2 * node + 1]);
}
node Get(int node, int l, int r, int ql, int qr) {
    if (r < ql || qr < l) return {-inf, inf, 0};
    if (ql <= l && r <= qr) return st[node];
    int mid = l + r >> 1;
    return Merge(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr));
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> arr[i];
    Init(1, 0, n - 1);
    while (m--) {
        int l, r, x;
        cin >> l >> r >> x;
        l -= 1; r -= 1;
        node ans = Get(1, 0, n - 1, l, r);
        if (ans.ans <= x) cout << 1 << en;
        else cout << 0 << en;
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void Init(int, int, int)':
sortbooks.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int mid = l + r >> 1;
      |               ~~^~~
sortbooks.cpp: In function 'node Get(int, int, int, int, int)':
sortbooks.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1450 ms 30960 KB Output is correct
2 Correct 1341 ms 30884 KB Output is correct
3 Correct 1359 ms 30952 KB Output is correct
4 Correct 1385 ms 30832 KB Output is correct
5 Correct 1355 ms 30868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 101 ms 4056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -