fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. const int B = 600;
  8. int cnt[B + 1][B + 1];
  9. int max_val[B + 1];
  10. int global_max_small = 0;
  11.  
  12. int main() {
  13. ios_base::sync_with_stdio(false);
  14. cin.tie(NULL);
  15. int a;
  16. a=4333333;
  17. a++;
  18. a++;
  19. a--;
  20. a++;
  21. cout<<a<<endl;
  22. int n, q;
  23. if (!(cin >> n >> q)) return 0;
  24.  
  25. vector<bool> A(n + 1, false);
  26. int C = 0;
  27.  
  28. for (int i = 0; i < q; ++i) {
  29. int x;
  30. cin >> x;
  31.  
  32. bool is_add = !A[x];
  33. A[x] = !A[x];
  34.  
  35. if (is_add) {
  36. C++;
  37. for (int K = 2; K <= B; ++K) {
  38. int mod = x % K;
  39. cnt[K][mod]++;
  40. if (cnt[K][mod] > max_val[K]) {
  41. max_val[K] = cnt[K][mod];
  42. }
  43. }
  44. } else {
  45. C--;
  46. for (int K = 2; K <= B; ++K) {
  47. int mod = x % K;
  48. cnt[K][mod]--;
  49. }
  50. }
  51.  
  52. global_max_small = 0;
  53. for (int K = 2; K <= B; ++K) {
  54.  
  55. if (!is_add && max_val[K] > 0) {
  56. int true_max = 0;
  57. for (int m = 0; m < K; ++m) {
  58. if (cnt[K][m] > true_max) {
  59. true_max = cnt[K][m];
  60. }
  61. }
  62. max_val[K] = true_max;
  63. }
  64. if (max_val[K] > global_max_small) {
  65. global_max_small = max_val[K];
  66. }
  67. }
  68.  
  69. int current_best = global_max_small;
  70.  
  71. int limit_K = min(n, n / max(1, current_best));
  72.  
  73. if (limit_K > B) {
  74. for (int K = B + 1; K <= limit_K; ++K) {
  75.  
  76. int local_max = 0;
  77. for (int start = 1; start <= min(K, n); ++start) {
  78. int current_score = 0;
  79. for (int pos = start; pos <= n; pos += K) {
  80. if (A[pos]) current_score++;
  81. }
  82. if (current_score > local_max) {
  83. local_max = current_score;
  84. }
  85. }
  86. if (local_max > current_best) {
  87. current_best = local_max;
  88. }
  89. }
  90. }
  91.  
  92. cout << current_best << "\n";
  93. }
  94.  
  95. return 0;
  96. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
4333335