Pagini recente » Cod sursa (job #575483) | Cod sursa (job #447855) | Cod sursa (job #486322) | Cod sursa (job #376922) | Cod sursa (job #1984341)
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include<iostream>
#include<queue>
#include<utility>
#define RRR ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define int ll
#define pp pair<int,int>
using namespace std;
vector <int> ar;
int n;
int bina(int x)
{
int low = 0;
int high = n;
int m = -1;
while (low <= high)
{
int mid = low + high >> 1;
// cout << mid << endl;
if (ar[mid] > x)
high = mid - 1;
else
{
m = max(low,m);
low = mid + 1;
}
}
return m;
}
int32_t main()
{
RRR
// freopen("text.txt","r",stdin);
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
cin >> n;
for (int i=0;i<n;i++)
{
int z;
cin >> z;
ar.push_back(z);
}
//cout << bina(3);
int q;
cin >> q;
for (int i=0;i<q;i++)
{
int a;
cin >> a;
int x;
cin >> x;
vector<int>::iterator low,up;
if (a == 0)
{
cout << bina(x) + 1 << "\n";
}
else if (a == 2)
{
low = lower_bound(ar.begin(),ar.end(),x);
cout << (low - ar.begin())+1 << "\n";
}
else if (a == 1)
{
up = upper_bound(ar.begin(),ar.end(),x);
cout << (up - ar.begin()) << "\n";
}
}
return 0;
}