QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#476917 | #5543. The Only Mode | yzkkai | WA | 0ms | 3832kb | C++20 | 2.0kb | 2024-07-13 21:35:00 | 2024-07-13 21:35:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define lowbit(x) ((x) & -(x))
inline void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int& i : a)
cin >> i;
vector<vector<int>> pref(n + 1, vector<int>(4));
for (int i = 1; i <= n; ++i) {
for (int j = 0;j < 4; ++j)
pref[i][j] = pref[i - 1][j];
++pref[i][a[i - 1]];
}
auto modify = [&](int x, int y, int val, vector<vector<int>> &bit) -> void {
for (; x < size(bit); x += lowbit(x))
for (int j = y; j < size(bit); j += lowbit(j))
bit[x][j] = min(bit[x][j], val);
return;
};
auto query = [&](int x, int y, const vector<vector<int>> &bit) -> int {
int ret = 1e9;
for (; x > 0; x -= lowbit(x))
for (int j = y; j > 0; j -= lowbit(j))
ret = min(ret, bit[x][j]);
return ret;
};
vector<int> ans(4);
for (int i = 0; i < 4; ++i) {
vector<vector<int>> b(n + 1, vector<int>(4));
for (int j = 0; j <= n; ++j) {
for (int k = 0, f = 0; k < 3; ++k) {
if (k == i) ++f;
b[j][k] = pref[j][i] - pref[j][k + f] + n + 1;
}
b[j][3] = j;
}
sort(b.begin(), b.end());
vector<vector<int>> bit(2 * n + 1, vector<int>(2 * n + 1, 1e9));
for (int j = 0, lst = 0; j <= n; ++j) {
ans[i] = max(ans[i], b[j][3] - query(b[j][1] - 1, b[j][2] - 1, bit));
if (b[lst][0] != b[j][0]) {
for (int k = lst; k < j; ++k)
modify(b[k][1], b[k][2], b[k][3], bit);
lst = j;
}
}
}
for (int i = 0; i < 4; ++i)
cout << ans[i] << " \n"[i == 3];
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
7 1 2 2 0 3 0 3
output:
4 1 5 3
result:
ok single line: '4 1 5 3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
12 2 0 1 0 2 1 1 0 2 3 3 3
output:
4 9 1 9
result:
ok single line: '4 9 1 9'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2 0 2
output:
1 0 1 0
result:
ok single line: '1 0 1 0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
12 3 0 2 2 1 0 2 1 3 3 2 3
output:
1 5 11 8
result:
ok single line: '1 5 11 8'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
1 1
output:
0 0 0 0
result:
wrong answer 1st lines differ - expected: '0 1 0 0', found: '0 0 0 0'