이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc 2 * no
#define rc 2 * no + 1
void setIO()
{
fast;
}
int n = 1e6 + 5;
vi a(n),tree(4 * n),b(n);
void build(int no,int l,int r)
{
if (l == r){tree[no] = a[l];return;}
int mid = (l + r)/2;
build(lc,l,mid),build(rc,mid + 1,r);
tree[no] = max(tree[lc],tree[rc]);
}
int MAX(int no,int l,int r,int i,int j)
{
if (l > j or i > r)return -1e9;
if (i <= l && r <= j)return tree[no];
int mid = (l + r)/2;
return max(MAX(lc,l,mid,i,j),MAX(rc,mid + 1,r,i,j));
}
int search(int i)
{
//binary search for the smallest j such that MAX(1,1,n,j,i) <= b[i]
int l = 1,r = i,pos = i;
while (l <= r){
int mid = (l + r)/2;
if (MAX(1,1,n,mid,i) <= b[i]){
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
return pos;
}
int main()
{
setIO();
cin>>n;
for (int i = 1;i<=n;i++)cin>>a[i]>>b[i];
build(1,1,n);
int cur = search(1);
int ans = 1 - cur + 1;
for (int i = 2;i<=n;i++){
int val = search(i);
int now = max(val,cur);
ans = max(ans,i - now + 1);
cur = max(cur,val);
}
cout<<ans;
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... |