给你一个包含N整数的数组,你必须回答K查询。每个查询都包含一个整数X,它是数组的(从 1 开始的索引)元素的索引。
为每个查询计算以下内容:
The number of segments containing the index X as the leftmost or the
rightmost element and the number at the index `X` is `>=` each element
of that segment.
Run Code Online (Sandbox Code Playgroud)
段形成示例:
您有 array {1, 2, 3}。可能的线段3是[2,3]和[1,2,3]和[3]。
2 的可能部分是[2],[1,2]
我通过暴力得到了解决方案。最坏情况的时间复杂度是O(n * k)
Input: Array[] = {4,2,1,3}, Queries[] = {1,4}
Output:
4
3
Explanation:
For first query 1 all possible …Run Code Online (Sandbox Code Playgroud) 我想了解getchar()函数在这里如何工作?
我读取了getchar()返回的下一个字符stdin,或者EOF到达了文件末尾。
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int decimal;
while(!isdigit(decimal=getchar()));
cout<<decimal;
}
Run Code Online (Sandbox Code Playgroud)
我输入25。输出50。我不明白为什么?怎么给50。