编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#5029 #1031. 统计 Compile Error 0 0 ms 0 K C++ 17 / 789 B t330034024 2024-02-25 15:07:30
显示原始代码
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 200005;
int n, m, a[N], num[N];

int read() {
    int f = 1, x = 0;
    char c;
    c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int main() {
    n = read(), m = read();

    int cnt;
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        if (a[i] == a[i - 1])
            num[i] = num[i - 1] + 1;
        else
            num[i] = 1;
    }

    int l, r;
    while (m--) {
        int ans = 0;
        l = read(), r = read();

        for (int i = r; i >= l;) {
            ans++;

            if (r - num[i] >= l)
                i -= num[i];

            else
                i = l - 1;
        }
        printf("%d\n", ans);
    }
}

编译信息

cc1plus: error: '::main' must return 'int'
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:56:12: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   56 |   printf("%d\n",ans);
      |           ~^    ~~~
      |            |    |
      |            int  long long int
      |           %lld