cpp
#include<iostream>
using namespace std;
#include<algorithm>
int n;
int arr[100010];
int f_left(int q)
{
int a = -1;
int left = 1, right = n;
int mid;
while (left < right)
{
mid = (left + right) / 2;
if (arr[mid] == q)
{
right = mid - 1;
//cout << "1";
}
else if (arr[mid] < q)
{
left = mid+1;
//cout << "2";
}
else
{
right = mid - 1;
//cout << "3";
}
}
return left;
}
int f_right(int q)
{
int a = -1;
int left = 1, right = n;
int mid;
while (left < right)
{
mid = (left + right) / 2;
if (arr[mid] == q)
{
left = mid + 1;
//cout << "4";
}
else if (arr[mid] > q)
{
right = mid - 1;
//cout << "5";
}
else
{
left = mid + 1;
//cout << "6";
}
}
return right;
}
int main()
{
int q;
cin >> n >> q;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
int left = f_left(q);
int right = f_right(q);
if (left ==-1&&right==-1)
{
cout << "-1 -1" << endl;
}
else
{
cout << left << " " << right << endl;
cout << right - left << endl;
}
return 0;
}
cpp
#include<iostream>
using namespace std;
int n;
int arr[60];
void f(int q)
{
int left = 1;
int right = n;
int mid;
int ans;
while (left < right)
{
mid = (left + right) / 2;
if (arr[mid] < q)
{
if (arr[mid + 1] > q)
{
cout << mid+1 << endl;
return;
}
left = mid + 1;
}
else
{
if (arr[mid - 1] < q)
{
cout << mid << endl;
return;
}
right = mid - 1;
}
}
}
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
int q;
cin >> q;
if (q < arr[1])
{
cout << 1 << endl;
}
else if (q > arr[n])
{
cout << n + 1 << endl;
}
else
{
f(q);
}
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<algorithm>
int n, k;
int arr[100010];
int main()
{
cin >> n >> k;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
int left = 1;
int right = 100000000;
int mid;
int ans = 0;
while (left <= right)
{
int res = 0;
mid = (left + right) / 2;
for (int i = 1;i <= n;i++)
{
res += (arr[i] / mid);
if (res > k)break;
}
if (res == k)
{
if (mid > ans)ans = mid;
left = mid + 1;
}
else if (res > k)
{
if (mid > ans)ans = mid;
left = mid + 1;
}
else
{
right = mid - 1;
}
}
cout << ans << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
int arr[27];
int main()
{
int n;
cin >> n;
char ch;
for (int i = 0;i < n;i++)
{
cin >> ch;
if (int(ch) >= 65 && int(ch) <= 90)
{
arr[int(ch) - 64] = 1;
}
else
{
arr[int(ch) - 96] = 1;
}
}
for (int i = 1;i <= 26;i++)
{
if (arr[i] != 1)
{
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}