版本比较
P14924 [GESP202512 八级] 宝石项链
正文
增加 6 行删除 6 行
39 行未改动4041424344454647484950515253545556575859606162636465666768697071727339 行未改动}signed main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> n >> m;for(int i = 1; i <= n; ++ i)cin >> a[i], a[i + n] = a[i];int r = 0, tot = 0;for(int i = 1; i <= n; ++ i){while(tot < m && r < 2 * n)if(!(cnt[a[++ r]] ++))++ tot;st[0][i] = r - i + 1;if(!(-- cnt[a[i]]))-- tot;}for(int i = 1; i < LOG; ++ i)for(int j = 1; j <= n; ++ j){int to = (j + st[i - 1][j] - 1) % n + 1;st[i][j] = min(st[i - 1][j] + st[i - 1][to], INF);}int ans = 0;for(int i = 1; i <= n; ++ i)ans = max(ans, jump(i));cout << ans;return 0;}```39 行未改动4041424344454647484950515253545556575859606162636465666768697071727339 行未改动}signed main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> n >> m;for(int i = 1; i <= n; ++ i)cin >> a[i], a[i + n] = a[i];int r = 0, tot = 0;for(int i = 1; i <= n; ++ i){while(tot < m && r < 2 * n)if(!(cnt[a[++ r]] ++))++ tot;st[0][i] = r - i + 1;if(!(-- cnt[a[i]]))-- tot;}for(int i = 1; i < LOG; ++ i)for(int j = 1; j <= n; ++ j){int to = (j + st[i - 1][j] - 1) % n + 1;st[i][j] = min(st[i - 1][j] + st[i - 1][to], INF);}int ans = 0;for(int i = 1; i <= n; ++ i)ans = max(ans, jump(i));cout << ans;return 0;}```