-
Notifications
You must be signed in to change notification settings - Fork 0
/
1987.cpp
54 lines (50 loc) · 1.06 KB
/
1987.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Author : Nguyen Le Minh
* Group : N3251
* Date : 8/4/2021
* Problem : 1987
*/
#include <iostream>
#include <stack>
#define max_size 1000012
using namespace std;
int n;
struct segment{
int l, r, ind;
}a[max_size];
stack<segment> s1;
void solve(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i].l >> a[i].r;
a[i].ind = i;
}
int q; cin >> q;
int pivot = 1;
while(q--){
int co; //Input coordinates
cin >> co;
while(pivot <= n && a[pivot].l <= co){ //Okay, check coordinate's left and push it into stack
s1.push(a[pivot]);
pivot++;
}
while(!s1.empty() && s1.top().r < co){
s1.pop();
}
if(s1.empty()){
cout << "-1" << endl;
continue;
}
segment t = s1.top();
if (co >= t.l && co <= t.r){
cout << t.ind << endl;
continue;
}
cout << -1 << endl;
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
solve();
return 0;
}