-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockccc15j5.cpp
38 lines (37 loc) · 1.05 KB
/
mockccc15j5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//upper and lower bounds with vectors
//Royal Guard
//Guard walks around, check how many buildings the guard will walk into
#include<bits/stdc++.h>
using namespace std;
int N,M;
vector<pair<int,int>> Xs,Ys;
int x,y,xf,yf;
int main()
{
cin.sync_with_stdio(0);cin.tie(0);
cin>>N;
for (int i=0;i<N;i++){
cin>>x>>y; //storing all of the building positions
Xs.push_back(make_pair(x,y));
Ys.push_back(make_pair(y,x));
}
sort(Xs.begin(),Xs.end());
sort(Ys.begin(),Ys.end());
cin>>M; //number of steps
cin>>x>>y;
long long int tot=0;
for (int i=0;i<M-1;i++){
//paths of the guard
cin>>xf>>yf;
if (x==xf){
//horizontal travel
tot += upper_bound(Xs.begin(),Xs.end(),make_pair(x,max(y,yf)))-lower_bound(Xs.begin(),Xs.end(),make_pair(x,min(y,yf)));
}
else{
tot+= upper_bound(Ys.begin(),Ys.end(),make_pair(y,max(x,xf)))-lower_bound(Ys.begin(),Ys.end(),make_pair(y,min(x,xf)));
}
x = xf;
y = yf;
}
cout<<tot<<endl;
}