QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253908#5543. The Only Modewarner1129TL 519ms100300kbC++203.9kb2023-11-17 19:37:592023-11-17 19:38:00

Judging History

你现在查看的是最新测评结果

  • [2023-11-17 19:38:00]
  • 评测
  • 测评结果:TL
  • 用时:519ms
  • 内存:100300kb
  • [2023-11-17 19:37:59]
  • 提交

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; }

cc_hash_table<int, cc_hash_table<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)) if (!val[i].empty())
            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;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3472kb

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: 3456kb

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: 3412kb

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: 3412kb

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: 1ms
memory: 3400kb

input:

1
1

output:

0 1 0 0

result:

ok single line: '0 1 0 0'

Test #6:

score: 0
Accepted
time: 16ms
memory: 3744kb

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: 376ms
memory: 8036kb

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: 278ms
memory: 6804kb

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: 314ms
memory: 7320kb

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: 363ms
memory: 7696kb

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: 353ms
memory: 7736kb

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: 465ms
memory: 44640kb

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: 519ms
memory: 100300kb

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...

output:


result: