Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. // O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
  2. #pragma GCC optimize("Ofast")
  3. #pragma GCC optimize("no-stack-protector")
  4. #pragma GCC optimize("unroll-loops")
  5. #pragma GCC optimize("fast-math")
  6. #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
  7. #include <iostream>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <set>
  11. #include <map>
  12. // #include <unordered_set>
  13. // #include <unordered_map>
  14. #include <stdio.h>
  15. #include <cstdio>
  16. #include <math.h>
  17. #include <cmath>
  18. #include <cstring>
  19. #include <queue>
  20. #include <deque>
  21. #include <random>
  22. #include <iomanip>
  23. #include <bitset>
  24. #include <cassert>
  25.  
  26. using namespace std;
  27.  
  28. #define y1 y11
  29. #define left left228
  30. #define right right228
  31. #define list list228
  32. #define all(v) v.begin(), v.end()
  33. #define tm tm228
  34. #define free free228
  35.  
  36.  
  37.  
  38. template<typename T> void uin(T &a, T b) {
  39. if (b < a) a = b;
  40. }
  41. template<typename T> void uax(T &a, T b) {
  42. if (b > a) a = b;
  43. }
  44.  
  45. const int N = 500 * 1000 + 228;
  46. const int C = 25;
  47.  
  48. int n, q;
  49. int a[N], allcnt[N];
  50. vector<int> pos[N];
  51. mt19937 rnd(rand());
  52. bool used[N];
  53.  
  54. int get(int x, int l, int r) {
  55. return upper_bound(all(pos[x]), r) - lower_bound(all(pos[x]), l);
  56. }
  57.  
  58. signed main() {
  59. ios_base::sync_with_stdio(false);
  60. cin.tie(0);
  61. cin >> n >> q;
  62. for (int i = 1; i <= n; ++i) {
  63. cin >> a[i];
  64. ++allcnt[a[i]];
  65. pos[a[i]].emplace_back(i);
  66. }
  67. int l, r, len;
  68. int p = 0;
  69. vector<int> bad;
  70. bad.reserve(N);
  71. while(q--) {
  72. cin >> l >> r;
  73. len = r - l + 1;
  74. bad.clear();
  75. int ans = 0;
  76. for (int it = 0; it < C; ++it) {
  77. p = l + rnd() % (r - l + 1);
  78. if (!used[a[p]] && allcnt[a[p]] * 2 > len) {
  79. if (get(a[p], l, r) * 2 > len) {
  80. ans = a[p];
  81. break;
  82. }
  83. used[a[p]]=1;
  84. bad.emplace_back(a[p]);
  85. }
  86. }
  87. for (int x : bad) {
  88. used[x] = 0;
  89. }
  90. cout << ans << '\n';
  91. }
  92. return 0;
  93. }
  94.  
  95. // RU_023
  96.  
  97. /*
  98.  
  99. 5 11
  100. ?
  101. + 1 2
  102. + 2 3
  103. + 3 4
  104. + 4 5
  105. + 5 1
  106. ?
  107. - 2 3
  108. ?
  109. - 4 5
  110. ?
  111.  
  112.  
  113. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement