QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#476922 | #5543. The Only Mode | yzkkai | ML | 72ms | 280856kb | C++20 | 2.0kb | 2024-07-13 21:37:10 | 2024-07-13 21:37:11 |
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) {
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;
}
ans[i] = max(ans[i], b[j][3] - query(b[j][1] - 1, b[j][2] - 1, bit));
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
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: 1ms
memory: 3864kb
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: 3568kb
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: 0
Accepted
time: 0ms
memory: 3824kb
input:
1 1
output:
0 1 0 0
result:
ok single line: '0 1 0 0'
Test #6:
score: 0
Accepted
time: 72ms
memory: 280856kb
input:
4207 3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...
output:
2330 1520 4207 1359
result:
ok single line: '2330 1520 4207 1359'
Test #7:
score: -100
Memory Limit Exceeded
input:
89925 0 0 0 3 0 3 0 2 3 2 3 1 0 0 0 2 2 1 3 3 0 0 1 0 0 3 0 1 0 0 1 1 0 0 1 2 1 3 1 2 1 2 2 1 0 2 2 3 0 0 1 0 2 3 2 3 0 0 1 0 0 1 2 1 3 0 0 0 2 1 1 0 1 3 2 2 0 0 2 3 2 3 3 1 3 3 0 2 0 2 2 0 2 1 3 0 1 1 0 0 1 0 3 1 2 2 2 0 2 0 2 3 2 0 0 2 3 3 1 0 1 2 2 2 1 2 0 0 3 2 3 0 1 1 3 3 0 0 0 3 0 2 0 0 2 3 1 ...