QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610722 | #8332. Two in One | hhhyh# | WA | 30ms | 20660kb | C++23 | 2.7kb | 2024-10-04 17:08:27 | 2024-10-04 17:08:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int long long
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
int qp(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
};
void solve()
{
int n;
cin >> n;
vector<int> a(n);
vector<int> cnt(n);
for (int i = 0; i < n; i++)
cin >> a[i], a[i]--, cnt[a[i]]++;
int c = max_element(all(cnt)) - cnt.begin();
int mx = cnt[c];
int lg = __lg(mx);
int ans = mx;
for (int i = 0; i < n; i++)
ans = max(ans, mx | cnt[i]);
vector<tuple<int, int, int>> Q;
int mask = (1 << lg + 1) - 1;
vector<vector<int>> pos(n);
for (int i = 0; i < n; i++)
pos[a[i]].push_back(i);
for (int i = lg; ~i; i--)
{
if (ans >> i & 1)
continue;
for (int j = 0; j < n; j++)
{
for (int k = i + 1; k <= lg; k++)
{
if (cnt[j] >> k & 1)
{
int val = cnt[j];
val -= 1 << k;
val |= (1 << i + 1) - 1;
for (int i = 0; i + val <= pos[j].size(); i++)
{
int l = i == 0 ? 0 : pos[j][i - 1] + 1;
int r = i + val < pos[j].size() ? pos[j][i + val] - 1 : n - 1;
Q.emplace_back(l, r, val);
}
break;
}
}
}
break;
};
int B = sqrt(n);
sort(all(Q), [&](auto a, auto b)
{
auto [l1,r1,w1]=a;
auto [l2,r2,w2]=b;
if(l1/B!=l2/B)return l1/B>l2/B;
else return r1/B<r2/B; });
int L = 0, R = 0;
vector<int> mcnt(n);
priority_queue<pair<int, int>> q;
auto oo = [&](int val)
{
while (mcnt[q.top().second] != q.top().first)
q.pop();
int x = q.top().first;
ans = max(ans, x | val);
};
auto add = [&](int p)
{
mcnt[p]++;
q.push({mcnt[p], p});
};
auto del = [&](int p)
{
mcnt[p]--;
q.push({mcnt[p], p});
};
for (auto [l, r, val] : Q)
{
while (R <= r)
add(a[R++]);
while (R - 1 > r)
del(a[--R]);
while (L + 1 < l)
del(a[L++]);
while (L > l)
add(--L);
oo(val);
}
cout << ans << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 3560kb
input:
1 9 1 1 1 1 1 2 2 2 2
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: -100
Wrong Answer
time: 30ms
memory: 20660kb
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 254 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
result:
wrong answer 31st numbers differ - expected: '255', found: '254'