1 条题解

  • 0
    @ 2024-9-25 17:45:54

    参考答案:

    #include<iostream>
    using namespace std;
    const int N = 10010, INF = 1e9;
    int q[N];
    int res;
    int main()
    {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) scanf("%d", &q[i]);
    
        for (int i = 0; i < n; ++i)
        {
            int minn = INF, maxx = -INF;
            for (int j = i; j < n; ++j)
            {
                minn = min(minn, q[j]);
                maxx = max(maxx, q[j]);
                if ((maxx - minn) == j - i) res++;
            }
        }
        cout << res << endl;
        return 0;
    
    }
    
    • 1

    信息

    ID
    5384
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    15
    已通过
    5
    上传者