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>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
template <class T> struct SparseTable {
std::vector<T> v;
std::vector<std::vector<int>> jump;
int level(int x) { return 31 - __builtin_clz(x); }
int comb(int a, int b) {
return v[a] == v[b] ? std::max(a, b) : (v[a] > v[b] ? a : b);
}
void init(const std::vector<T>& _v) {
v = _v;
jump = {std::vector<int>((int)v.size())};
iota(jump[0].begin(), jump[0].end(), 0);
for (int j = 1; (1 << j) <= (int)v.size(); j++) {
jump.push_back(std::vector<int>((int)v.size() - (1 << j) + 1));
for (int i = 0; i < (int)jump[j].size(); i++) {
jump[j][i] = comb(jump[j - 1][i], jump[j - 1][i + (1 << (j - 1))]);
}
}
}
int index(int l, int r) {
assert(l <= r);
int d = level(r - l + 1);
return comb(jump[d][l], jump[d][r - (1 << d) + 1]);
}
T query(int l, int r) {
return v[index(l, r)];
}
};
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n;cin >> n;
vector<pair<int,int>> a(n);
for(auto &e : a)cin >> e.first >> e.second;
vector<int> temp(n);
for(int i = 0;i<n;i++)
temp[i] = a[i].first;
SparseTable<int> rq;
rq.init(temp);
vector<int> leftmost(n);
for(int i =0;i<n;i++){
int l = 0,r = i;
while(l < r){
int mid = (l + r)/2;
if(rq.query(mid,i) <= a[i].second)
r = mid;
else
l = mid + 1;
}
leftmost[i] = l;
}
for(int i = 1;i<leftmost.size();i++)
leftmost[i] = max(leftmost[i], leftmost[i - 1]);
for(int i = 0;i<n;i++)
leftmost[i] = i - leftmost[i] + 1;
deb(leftmost);
cout << *max_element(leftmost.begin(),leftmost.end());
}
Compilation message (stderr)
tem.cpp: In function 'int main()':
tem.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 1;i<leftmost.size();i++)
| ~^~~~~~~~~~~~~~~~
# | 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... |