QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253899 | #5543. The Only Mode | warner1129 | TL | 1048ms | 78444kb | C++20 | 3.6kb | 2023-11-17 19:27:08 | 2023-11-17 19:27:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<i128, i128>;
template<class T>
inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
Pt operator+(Pt a, Pt b) { return {a.ff + b.ff, a.ss + b.ss}; }
Pt operator-(Pt a, Pt b) { return {a.ff - b.ff, a.ss - b.ss}; }
i128 operator^(Pt a, Pt b) { return a.ff * b.ss - a.ss * b.ff; }
i128 cro(Pt a, Pt b, Pt c) { return (b - a) ^ (c - a); }
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
unordered_map<int, unordered_map<int, int>> val;
struct BIT2D {
static const int kN = 2e5;
BIT2D() {
val.clear();
}
int lowbit(int x) { return x & -x; }
void add(int x, int y, int v) {
for (int i = x; i <= kN; i += lowbit(i))
for (int j = y; j <= kN; j += lowbit(j))
if (auto it = val[i].find(j); it != val[i].end())
chmin(it->ss, v);
else val[i][j] = v;
}
int qry(int x, int y) {
int r = inf<int>;
for (int i = x; i > 0; i -= lowbit(i))
for (int j = y; j > 0; j -= lowbit(j))
if (auto it = val[i].find(j); it != val[i].end())
chmin(r, it->ss);
return r;
}
};
void solve() {
int n;
cin >> n;
vector<int> A(n);
for (int &x : A) cin >> x;
auto Swap = [&](int a, int b) {
for (int &x : A) {
if (x == a) x = b;
else if (x == b) x = a;
}
};
auto cal = [&]() -> int {
vector f(3, vector<int>(n + 1));
f[0][0] = f[1][0] = f[2][0] = int(1e5);
for (int i = 1; i <= n; i++) {
for (int j : {0, 1, 2}) {
f[j][i] = f[j][i - 1] + (A[i - 1] == 0) - (A[i - 1] == j + 1);
}
}
vector<pair<int, int>> pt;
for (int i = 0; i <= n; i++) {
pt.emplace_back(f[1][i], f[2][i]);
}
BIT2D bit;
vector<int> ord(n + 1);
iota(all(ord), 0);
sort(all(ord), [&](int a, int b) {
return f[0][a] < f[0][b];
});
int ans = 0;
vector<int> buf;
for (auto l = ord.begin(), r = ord.begin(); l != ord.end(); l = r) {
while (r != ord.end() and f[0][*l] == f[0][*r]) r++;
for (auto i = l; i != r; i++) {
chmax(ans, *i - bit.qry(f[1][*i] - 1, f[2][*i] - 1));
}
for (auto i = l; i != r; i++) {
bit.add(f[1][*i], f[2][*i], *i);
}
}
return ans;
};
for (int p : {0, 1, 2, 3}) {
Swap(p, 0);
cout << cal() << " \n"[p == 3];
Swap(p, 0);
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3668kb
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: 3548kb
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: 3796kb
input:
2 0 2
output:
1 0 1 0
result:
ok single line: '1 0 1 0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3536kb
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: 3480kb
input:
1 1
output:
0 1 0 0
result:
ok single line: '0 1 0 0'
Test #6:
score: 0
Accepted
time: 33ms
memory: 3936kb
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: 0
Accepted
time: 759ms
memory: 7836kb
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 ...
output:
89925 49888 75725 38162
result:
ok single line: '89925 49888 75725 38162'
Test #8:
score: 0
Accepted
time: 544ms
memory: 6356kb
input:
64937 1 1 0 2 1 1 3 1 1 1 2 0 3 1 1 2 1 2 2 1 0 2 1 1 1 1 1 0 3 1 0 2 1 0 0 0 0 2 1 2 1 2 2 1 2 3 2 1 2 1 3 0 1 3 0 0 1 3 1 2 2 2 0 3 3 1 3 0 3 3 2 0 1 1 2 0 3 3 3 2 1 0 1 0 1 3 0 0 2 1 0 3 3 1 2 3 2 1 1 0 0 3 1 1 2 1 0 2 1 0 0 1 1 3 0 1 2 1 3 2 0 3 1 2 1 2 0 0 0 1 1 2 3 3 2 1 1 1 2 1 3 1 2 2 2 0 1 ...
output:
64937 61901 51387 63870
result:
ok single line: '64937 61901 51387 63870'
Test #9:
score: 0
Accepted
time: 598ms
memory: 7180kb
input:
73423 1 2 2 0 0 0 0 2 1 2 1 2 1 3 1 3 3 0 1 2 2 0 0 0 3 2 1 1 0 3 0 2 1 3 1 1 2 3 0 1 2 1 0 0 0 3 3 0 3 2 3 3 1 1 3 2 0 0 0 3 2 0 0 2 3 3 3 3 3 2 3 2 2 2 3 3 0 1 1 2 2 2 1 2 2 1 1 2 1 2 2 3 0 3 0 2 2 2 1 2 1 1 2 3 0 1 3 2 0 3 3 3 0 2 2 2 3 1 0 1 0 1 1 3 0 0 2 1 1 3 1 3 3 2 0 2 2 1 1 0 1 0 2 3 1 2 3 ...
output:
36577 18616 60210 73423
result:
ok single line: '36577 18616 60210 73423'
Test #10:
score: 0
Accepted
time: 717ms
memory: 7568kb
input:
82517 2 1 1 0 2 0 3 1 3 1 3 3 2 2 3 0 3 2 2 0 2 1 0 2 2 3 2 0 1 0 1 2 2 1 1 1 3 2 2 0 1 0 0 3 3 1 1 0 3 1 3 1 2 3 3 3 3 3 2 1 3 1 3 0 2 0 2 0 2 2 2 2 2 1 2 1 3 3 2 3 2 3 0 2 0 1 0 0 3 2 1 1 0 1 2 1 1 0 1 3 1 3 3 2 2 3 0 2 1 3 2 1 0 1 2 3 2 2 3 3 1 0 2 0 3 2 3 0 1 2 0 3 3 0 2 1 1 3 3 2 2 0 2 2 1 1 2 ...
output:
50863 68187 40176 82517
result:
ok single line: '50863 68187 40176 82517'
Test #11:
score: 0
Accepted
time: 672ms
memory: 7856kb
input:
79392 0 2 2 2 0 3 2 3 1 1 1 0 0 3 1 3 3 0 2 2 0 0 0 2 1 0 2 2 2 1 2 3 2 0 3 3 3 2 0 1 0 1 1 1 0 1 0 1 0 2 3 3 0 1 2 3 0 1 0 1 0 1 2 2 1 3 0 0 1 3 1 2 2 1 0 0 2 1 0 0 2 2 3 1 3 0 3 2 0 0 0 0 3 3 0 0 2 2 0 2 0 2 3 1 0 2 2 1 2 2 0 3 3 3 2 1 3 1 1 1 1 2 0 0 1 1 1 0 1 1 1 3 3 0 2 3 1 1 0 1 2 3 1 3 3 0 0 ...
output:
68113 34911 26794 79392
result:
ok single line: '68113 34911 26794 79392'
Test #12:
score: 0
Accepted
time: 952ms
memory: 35004kb
input:
100000 2 0 0 1 0 2 3 3 0 2 1 2 0 2 0 3 0 0 2 0 1 1 0 1 1 1 1 0 2 2 0 1 0 1 0 0 0 3 1 0 3 0 1 1 1 3 1 0 1 3 1 1 1 0 1 3 0 1 1 0 1 3 0 0 0 0 0 0 0 1 0 0 1 3 1 3 0 1 0 0 2 1 1 2 2 0 3 3 2 1 1 0 0 1 1 2 0 1 2 0 3 3 1 1 1 0 3 3 0 1 3 0 1 0 2 1 3 3 2 3 2 0 2 3 0 2 2 2 0 1 0 0 1 0 2 1 1 1 2 1 2 1 1 0 3 1 1...
output:
448 100000 52 33
result:
ok single line: '448 100000 52 33'
Test #13:
score: 0
Accepted
time: 1048ms
memory: 78444kb
input:
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 3 0 0 0 0 0 3 0 0 0 0 0...
output:
100000 0 0 11
result:
ok single line: '100000 0 0 11'
Test #14:
score: -100
Time Limit Exceeded
input:
100000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...