이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, q, where[N], pref[N];
struct Event{
int l, r;
bool operator < (const Event &sc) const{
if(r == sc.r) return l < sc.l;
else return r < sc.r;
}
};
Event arr[N];
bool canmove(Event a, Event b){
return b.l <= a.r && a.r <= b.r;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> arr[i].l >> arr[i].r;
vector<pair<Event, int>> v;
for(int i = 1; i <= n; i++) v.push_back({arr[i], i});
sort(v.begin(), v.end());
for(int i = 1; i < n; i++) pref[i] = pref[i - 1] + canmove(v[i - 1].first, v[i].first);
for(int i = 0; i < n; i++) where[v[i].second] = i;
while(q--){
int s, e;
cin >> s >> e;
s = where[s], e = where[e];
if(s <= e){
if(pref[e] - pref[s] == (e - s)) cout << e - s << "\n";
else cout << "impossible\n";
}
else cout << "impossible\n";
}
}
# | 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... |