提交时间:2023-05-20 17:24:49
运行 ID: 74195
#include <stdio.h> #define N 100005 int n, m, i, j, k, p, ans, a[N], c[N], r[N]; int main() { scanf("%d%d", &n, &m); for (i = p = 1; i <= m; i++) { scanf("%d", &a[i]); if (++c[a[i]] > 1) { while (1) { r[p] = i; if (--c[a[p++]] == 1) { break; } } // 预处理从p往右扩展最远的位置 } } while (p < i) { r[p++] = i + n; } for (i = 0; i < n; i++) { if (r[1] - 1 < n - i) { continue; } for (j = n - i + 1; j <= m; j += n) { if (r[j] - j < n) { break; } } if (j > m) { ans++; } } printf("%d\n", ans); return 0; }