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 <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
#define int long long
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define UseOFF ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
#define sz size
#define ins insert
#define new junkedseduneon
#define prev usfdjik
const ll N = 2e6 + 111;
pair <ll, ll> a[N];
map <pair <ll, ll>, ll> ans;
map <pair <ll, ll>, ll> mp;
void solve() {
ll n, q;
cin >> n >> q;
vector < pair <ll, ll> > v;
for(int i = 1; i <= n; i++) {
cin >> a[i].ff >> a[i].ss;
v.pb(make_pair(a[i].ss, a[i].ff));
mp[{a[i].ff, a[i].ss}] = i;
}
sort(v.begin(), v.end());
for(int i = 0; i < v.sz(); i++) {
ans[{v[i].ss, v[i].ff}] = i;
//cout << v[i].ss << " " << v[i].ff << " " << i << '\n';
}
for(int i = 1; i <= q; i++) {
ll s, f;
cin >> s >> f;
//cout << i << " - " << q << endl;
if(ans[{a[f].ff, a[f].ss}] - ans[{a[s].ff, a[s].ss}] < 0) {
cout << "impossible\n";
}
else {
//cout << s << " " << f << " || " << a[f].ff << " " << a[f].ss << " || " << a[s].ff << " " << a[s].ss << '\n';
cout << ans[{a[f].ff, a[f].ss}] - ans[{a[s].ff, a[s].ss}] << '\n';
}
}
}
signed main()
{
UseOFF
ll ttt = 1;
//cin >> ttt;
while(ttt--)
{
solve();
}
}
Compilation message (stderr)
events.cpp: In function 'void solve()':
events.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < v.sz(); 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... |