-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path369.cpp
66 lines (62 loc) · 1.36 KB
/
369.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
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
void solve()
{
int n,q;
cin>>n>>q;
int arr[n];
int count,flag=0;
pair <int,int>p[q];
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
for(int i=0;i<q;i++)
{
cin>>p[i].first>>p[i].second;
int x = p[i].second;
switch(p[i].first){
case 1:
flag=0;
for(int j=0;j<n;j++)
{
if(x<=arr[j]){cout<<arr[j]<<" ";flag=1;break;}
}
if(flag==0)cout<<-1<<" ";
break;
case 2:
flag=0;
for(int j=0;j<n;j++)
{
if(x<arr[j]){cout<<arr[j]<<" ";flag=1;break;}
}
if(flag==0)cout<<-1<<" ";
break;
case 3:
flag=0;
for(int j=n-1;j>=0;j--)
{
if(x>=arr[j]){cout<<j+1<<" ";flag=1;break;}
}
if(flag==0)cout<<0<<" ";
break;
case 4:
flag=0;
for(int j=n-1;j>=0;j--)
{
if(x>arr[j]){cout<<j+1<<" ";flag=1;break;}
}
if(flag==0)cout<<0<<" ";
break;
default:
cout <<-1<<" ";
}
}
cout<<endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int _t;cin>>_t;while(_t--)
solve();
}