This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
vector<int> t;
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;
t.resize(2*n);
for (int i = n; i < 2*n; ++i) {
t[i] = mn[i-n];
}
for (int i = n-1; i > 0; --i) {
t[i] = max(t[i*2], t[i*2+1]);
}
}
};
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... |