QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400745#8332. Two in OneasxziillWA 46ms3864kbC++231.9kb2024-04-27 15:48:472024-04-27 15:48:47

Judging History

你现在查看的是最新测评结果

  • [2024-04-27 15:48:47]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:3864kb
  • [2024-04-27 15:48:47]
  • 提交

answer

#include <bits/stdc++.h>

using ll = long long;

void solve() {
  int n;
  std::cin >> n;
  std::vector<std::vector<int>> c(n);
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    a--;
    c[a].push_back(i);
  }

  std::vector<std::pair<int, int>> a;
  for (int i = 0; i < n; i++) {
    if (!c[i].empty()) {
      a.emplace_back(-c[i].size(), i);
    }
  }

  if (a.size() == 1) {
    std::cout << (-a[0].first) << "\n";
    return;
  }

  std::sort(a.begin(), a.end());
  auto [x, px] = a[0];
  x = -x;
  int j;
  for (j = 1; j < a.size(); j++) {
    if (a[j].first != -x) {
      break;
    } 
  }
  if (j == a.size()) j--;
  auto [y, py] = a[j];
  y = -y;

  int ans = x | y;
  int len = 1;
  while ((len * 2) <= y) {
    len *= 2;
  }
  len -= 1;

  // std::cout << px << " " << py << " " << len << "\n";
  for (int i = 0; i + len <= y; i++) {
    int l = (i == 0 ? 0 : c[py][i - 1] + 1);
    int r = (i + len == y ? n : c[py][i + len]);
    auto p = std::lower_bound(c[px].begin(), c[px].end(), l) - c[px].begin();
    int cnt = 0;
    for (int j = p; j < x; j++) {
      if (c[px][j] >= r) break;
      cnt += 1;
    }
    // std::cout << l << " " << r << " " << cnt << "\n";
    ans = std::max(ans, cnt | len);
  }
  std::swap(x, y);
  std::swap(px, py);
  len = 1;
  while ((len * 2) <= y) {
    len *= 2;
  }
  len -= 1;

  for (int i = 0; i + len <= y; i++) {
    int l = (i == 0 ? 0 : c[py][i - 1] + 1);
    int r = (i + len == y ? n : c[py][i + len]);
    auto p = std::lower_bound(c[px].begin(), c[px].end(), l) - c[px].begin();
    int cnt = 0;
    for (int j = p; j < x; j++) {
      if (c[px][j] >= r) break;
      cnt += 1;
    }
    ans = std::max(ans, cnt | len);
  }
  std::cout << ans << "\n";
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t;
  std::cin >> t;
  while (t--) {
    solve();
  }    
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

1
7
1 2 3 4 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1
9
1 1 1 1 1 2 2 2 2

output:

7

result:

ok 1 number(s): "7"

Test #3:

score: 0
Accepted
time: 20ms
memory: 3832kb

input:

50
10000
72 65 90 94 67 93 41 43 54 83 31 34 38 37 44 42 92 63 66 79 90 45 41 40 19 54 34 90 13 74 40 77 41 57 74 86 91 79 34 39 21 88 90 57 23 31 8 15 80 27 45 38 53 96 51 82 70 71 19 75 62 95 31 67 99 97 94 29 90 7 95 82 61 98 62 77 43 65 66 30 41 69 38 79 51 9 63 77 13 30 72 70 67 93 92 45 74 50 ...

output:

255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255

result:

ok 50 numbers

Test #4:

score: 0
Accepted
time: 46ms
memory: 3616kb

input:

79114
7
1 2 4 3 2 3 7
7
1 2 4 7 4 1 5
6
4 2 2 4 2 1
7
1 2 1 4 7 3 2
7
1 2 4 7 1 1 3
7
1 2 6 1 5 2 5
6
5 2 6 1 2 5
7
1 1 7 6 6 5 2
7
1 2 5 6 6 7 7
7
1 1 2 7 2 3 6
7
1 1 1 4 6 2 2
7
1 1 5 7 3 5 2
7
1 1 7 6 2 2 5
6
4 3 4 6 3 1
6
4 4 3 2 3 1
7
1 1 2 3 7 6 2
6
1 2 5 6 3 4
7
1 1 1 1 4 7 6
6
2 6 6 2 5 3
6
...

output:

3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
1
5
3
3
3
3
3
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
6
3
3
3
3
5
3
3
3
5
3
3
3
3
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
3
5
3
3
3
1
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
...

result:

ok 79114 numbers

Test #5:

score: -100
Wrong Answer
time: 45ms
memory: 3864kb

input:

50000
10
6 3 8 5 4 6 3 5 3 9
10
10 4 3 10 4 5 2 7 8 10
10
10 6 2 2 4 9 7 3 3 4
10
1 2 9 7 5 2 1 2 10 1
10
2 8 2 3 7 8 3 5 10 5
10
5 6 10 2 7 3 5 10 5 4
10
3 4 4 2 2 1 1 8 5 10
10
3 3 3 8 5 7 3 6 7 9
10
10 6 5 3 2 8 10 9 9 4
10
5 8 6 2 10 5 8 8 10 7
10
5 8 2 10 2 2 9 5 4 2
10
7 6 4 7 5 9 2 2 1 7
10
7...

output:

3
3
3
3
3
3
3
6
3
3
6
3
3
3
6
3
3
3
3
6
3
3
3
3
3
3
3
3
6
3
6
3
3
3
6
3
6
3
7
3
3
6
3
3
3
6
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
6
3
3
3
3
3
3
3
3
3
5
3
3
7
3
3
3
3
3
3
6
3
3
3
6
3
3
3
7
3
6
3
3
3
3
3
3
3
6
3
3
5
3
3
6
7
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
7
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
6
3
7
3
3
3
3
3
3
6
3
...

result:

wrong answer 212th numbers differ - expected: '7', found: '6'