#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e
using vp=vec(pii);
signed main(){
_3HspL4A;
int n;
cin>>n;
vp a(n);
rep(i,n){
cin>>a[i].fi>>a[i].se;
}
// vi tmp;
// rep(i,n){
// tmp.pb(a[i].fi);
// tmp.pb(a[i].se);
// }
// sort(tmp.begin(),tmp.end());
// tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
// rep(i,n){
// a[i].fi=lower_bound(tmp.begin(),tmp.end(),a[i].fi)-tmp.begin();
// a[i].se=lower_bound(tmp.begin(),tmp.end(),a[i].se)-tmp.begin();
// }
int q;
cin>>q;
rep(_,q){
int s,t;
cin>>s>>t;
s-=1;
int l=a[s].fi,r=a[s].se;
int cnt=1;
for(int j=s+1;j<t;j++){
if(a[j].fi>r or a[j].se<l){
l=min(l,a[j].fi);
r=max(r,a[j].se);
}else{
cnt++;
l=a[j].fi;
r=a[j].se;
}
}
print(cnt);
}
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
1876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |