이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#endif
using namespace std;
#define int int64_t
template <class T>
istream &operator>>(istream &in, vector<T> &v)
{
for (T &x : v)
in >> x;
return in;
}
struct Range
{
int s, e, i;
bool operator<(Range other)
{
return tuple<int, int, int>{s, e, i} < tuple<int, int, int>{other.s, other.e, other.i};
}
};
int n, q;
vector<Range> ranges, sR;
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> n >> q;
ranges = vector<Range>(n);
for (int i = 0; i < n; i++)
{
cin >> ranges[i].s >> ranges[i].e;
ranges[i].i = i;
}
sR = ranges;
sort(sR.begin(), sR.end());
while (q--)
{
int s, e;
cin >> s >> e;
s--, e--;
if (s == e)
{
cout << "0\n";
continue;
}
set<pair<int, int>> ongoing;
int t = ranges[s].e;
int i = 0;
int cost = 0;
while (true)
{
while (i < n && sR[i].s <= t)
{
if (sR[i].e >= t)
ongoing.insert({sR[i].e, sR[i].i});
i++;
}
while (ongoing.size() && prev(ongoing.end())->first > ranges[e].e)
ongoing.erase(prev(ongoing.end()));
if (ongoing.size() == 0)
{
cout << "impossible\n";
break;
}
cost++;
if (prev(ongoing.end())->second == e)
{
cout << cost << "\n";
break;
}
else
{
t = prev(ongoing.end())->first;
ongoing = set<pair<int, int>>();
}
}
}
}
# | 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... |