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>
#define endl '\n'
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 1e6 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n;
int ad[MAXN], au[MAXN];
int inf = -1e9-10;
void read()
{
cin >> n;
int xx, yy;
for (int i = 1; i <= n; ++ i)
{
cin >> ad[i] >> au[i];
}
}
int t[MAXN * 4];
void make_tree(int i, int l, int r)
{
if(l == r)
{
t[i] = ad[l];
return;
}
int mid = (l + r)/2;
make_tree(2*i, l, mid);
make_tree(2*i+1, mid+1, r);
t[i] = max(t[2*i], t[2*i+1]);
}
int ql, qr;
int query(int i, int l, int r)
{
if(qr < l || ql > r)return inf;
if(ql <= l && r <= qr)return t[i];
int mid = (l + r)/2;
return max(query(2*i, l, mid), query(2*i+1, mid+1, r));
}
int main()
{
speed();
read();
make_tree(1, 1, n);
int ans = 0;
int last = 1;
int left, right, mid, border, maxx;
for (int i = 1; i <= n; ++ i)
{
left = last;
right = i;
border = i;
ql = last;
qr = i;
maxx = query(1, 1, n);
if(maxx <= au[i])
{
ans = max(ans, i - last + 1);
continue;
}
while(left <= right)
{
mid = (left + right)/2;
ql = mid;
qr = i;
maxx = query(1, 1, n);
if(maxx > au[i])
{
left = mid + 1;
}
else
{
border = mid;
right = mid - 1;
}
}
last = border;
//cout << i << " " << border << endl;
ans = max(ans, i - border + 1);
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
tem.cpp: In function 'void read()':
tem.cpp:18:9: warning: unused variable 'xx' [-Wunused-variable]
18 | int xx, yy;
| ^~
tem.cpp:18:13: warning: unused variable 'yy' [-Wunused-variable]
18 | int xx, yy;
| ^~
# | 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... |