이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#pragma GCC optimize("unroll-loops", "Ofast")
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using ll = long long;
const int mod = 1e9+7;
const int mxN = 1e6;
int mn[mxN], mx[mxN];
struct SegTree {
int n;
int t[2*mxN];
void build() {
for (int i = n-1; i > 0; --i) {
t[i] = max(t[i*2], t[i*2+1]);
}
}
int query(int l, int r) {
int ret = -1e9;
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l&1) ret = max(ret, t[l++]);
if (r&1) ret = max(ret, t[--r]);
}
return ret;
}
SegTree(int _n) {
n = _n;
for (int i = 0; i < n; ++i) t[i+n] = mn[i];
}
};
void solve(int tc) {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> mn[i] >> mx[i];
}
SegTree seg(n);
int lo = 0, hi = n-1;
int m = -1e9;
int ans = 0;
for (int i = 0; i < n; ++i) {
if (mx[i] < m) {
++lo;
hi = i;
while (lo < hi) {
int mid = (lo + hi) / 2;
int q = seg.query(mid, i);
if (mx[i] < q) lo = mid+1;
else hi = mid;
}
m = seg.query(lo, i);
}
m = max(m, mn[i]);
ans = max(ans, i - lo + 1);
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
# | 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... |
# | 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... |