QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253961 | #5543. The Only Mode | warner1129 | WA | 1ms | 3408kb | C++20 | 4.0kb | 2023-11-17 20:52:18 | 2023-11-17 20:52:19 |
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;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template<class T>
using BST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// __gnu_pbds::priority_queue<node, decltype(cmp), pairing_heap_tag> pq(cmp);
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; }
struct BIT {
vector<int> v;
int n;
BIT(int _n) : n{_n}, v(_n, inf<int>) {}
int lowbit(int x) { return x & -x; }
void add(int p, int x) {
for (int i = p + 1; i <= n; i += lowbit(i))
chmin(v[i - 1], x);
}
void reset(int p) {
for (int i = p + 1; i <= n; i += lowbit(i))
v[i - 1] = inf<int>;
}
int qry(int p) {
int r = inf<int>;
for (int i = p + 1; i > 0; i -= lowbit(i))
chmin(r, v[i - 1]);
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] = n + 3;
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<int> ord(n + 1);
iota(all(ord), 0);
sort(all(ord), [&](int a, int b) {
return f[0][a] < f[0][b];
if (f[0][a] != f[0][b]) return f[0][a] < f[0][b];
if (f[1][a] != f[1][b]) return f[1][a] > f[1][b];
return f[2][a] > f[2][b];
});
auto cmp = [&](int a, int b) {
return f[1][a] < f[1][b];
};
BIT bit(n * 2 + 5);
auto cdq = [&](auto self, auto l, auto r) -> int {
if (r - l <= 1) return 0;
auto mid = l + (r - l) / 2;
int ans = max(self(self, l, mid), self(self, mid, r));
for (auto i = l, j = mid; j != r; j++) {
while (i != mid and cmp(*i, *j)) {
bit.add(f[2][*i], *i);
i++;
}
chmax(ans, *j - bit.qry(f[2][*j] - 1));
}
for (auto i = l; i < mid; i++) bit.reset(f[2][*i]);
sort(l, r, cmp);
return ans;
};
return cdq(cdq, all(ord));
};
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3408kb
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: -100
Wrong Answer
time: 0ms
memory: 3388kb
input:
12 2 0 1 0 2 1 1 0 2 3 3 3
output:
10 10 6 10
result:
wrong answer 1st lines differ - expected: '4 9 1 9', found: '10 10 6 10'