이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Node { int max, maxInv; vector<int> nums; } tree[4000010];
int N, M, A[1000010]; const int INF = 2000000010;
Node comb(Node A, Node B) { Node res;
merge(A.nums.begin(), A.nums.end(), B.nums.begin(), B.nums.end(), back_inserter(res.nums));
res.max = max(A.max, B.max);
int L = A.max; int pos = lower_bound(B.nums.begin(), B.nums.end(), L) - B.nums.begin() - 1;
if (pos == -1) { res.maxInv = max(A.maxInv, B.maxInv); return res; }
int nInv = L + res.nums[pos]; res.maxInv = max(max(A.maxInv, B.maxInv), nInv); return res;
}
void build(int x, int l, int r) { int mid = (l + r) / 2;
if (l == r) { tree[x].max = A[l]; tree[x].nums = vector<int>(1, A[l]); return ; }
build(2 * x, l, mid); build(2 * x + 1, mid + 1, r); tree[x] = comb(tree[2 * x], tree[2 * x + 1]);
}
Node query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
if (r < tl || l > tr) return Node{0, 0, vector<int>(0)}; if (tl <= l && r <= tr) return tree[x];
return comb(query(2 * x, l, mid, tl, tr), query(2 * x + 1, mid + 1, r, tl, tr));
}
int main() {
cin >> N >> M; for (int i = 1; i <= N; i++) cin >> A[i];
build(1, 1, N); for (int i = 0; i < M; i++) { int A, B, M; cin >> A >> B >> M;
Node CUR = query(1, 1, N, A, B); cout << (CUR.maxInv <= M) << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'Node query(int, int, int, int, int)':
sortbooks.cpp:26:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
26 | if (r < tl || l > tr) return Node{0, 0, vector<int>(0)}; if (tl <= l && r <= tr) return tree[x];
| ^~
sortbooks.cpp:26:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
26 | if (r < tl || l > tr) return Node{0, 0, vector<int>(0)}; if (tl <= l && r <= tr) return tree[x];
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |