小编gup*_*r54的帖子

计算 A[i] 最右或最左且为 max 的段数

给你一个包含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)

algorithm data-structures

3
推荐指数
1
解决办法
1850
查看次数

如何getchar()函数输出

我想了解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。

c++ getchar

0
推荐指数
1
解决办法
60
查看次数

标签 统计

algorithm ×1

c++ ×1

data-structures ×1

getchar ×1