提交时间:2022-04-22 20:23:56

运行 ID: 37848

#include <iostream> #include <algorithm> const int N = 1e5 + 7, M = 5e7; int n, k, r[N], a[N], vis[M], ans, mx; int read() { int ans = 0; bool neg = false; char c = getchar(); while (c!='-' && !isdigit(c)) c = getchar(); if (c == '-') neg = true, c = getchar(); while (isdigit(c)) ans = 10*ans + c-'0', c = getchar(); return neg ? -ans : ans; } int main(){ n = read(), k = read(), r[1] = read(); for(int i = 1; i <= n; ++i){ a[i] = r[i]%4; r[i+1] = (r[i]*6807+2831) % 201701; } for (int i = 1; i <= n-k+1; i++) { int part = 0; for (int j = 1; j <= k; j++){ part += a[i+j]; part *= 4; } vis[part]++; mx = std::max(mx, part); } for (int i = 1; i <= mx; i++) if (vis[i]) ans++; printf("%d", ans); return 0; }