QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#253858#5543. The Only Modewarner1129WA 0ms3508kbC++204.1kb2023-11-17 17:41:352023-11-17 17:41:36

Judging History

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

  • [2023-11-17 17:41:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3508kb
  • [2023-11-17 17:41:35]
  • 提交

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

struct BIT2D {
    vector<vector<int>> val;
    vector<vector<int>> Y;
    vector<int> X;
    int lowbit(int x) { return x & -x; }
    int getp(const vector<int> &v, int x) {
        return upper_bound(all(v), x) - v.begin();
    }
    BIT2D(const vector<pair<int, int>> &pos) {
        for (auto [x, y] : pos) {
            X.push_back(x);
        }
        auto fix = [&](vector<int> &V) {
            sort(all(V));
            V.erase(unique(all(V)), V.end());
        };
        fix(X);
        Y.resize(X.size() + 1);
        for (auto [x, y] : pos) {
            for (int i = getp(X, x); i <= X.size(); i += lowbit(i)) {
                Y[i].push_back(y);
            }
        }
        for (auto &v : Y) {
            fix(v);
            val.emplace_back(v.size() + 1, inf<int>);
        }
    }
    void add(int x, int y, int v) {
        for (int i = getp(X, x); i <= X.size(); i += lowbit(i))
            for (int j = getp(Y[i], y); j <= Y[i].size(); j += lowbit(j))
                chmin(val[i][j], v);
    }
    int qry(int x, int y) {
        int r = inf<int>;
        for (int i = getp(X, x); i > 0; i -= lowbit(i))
            for (int j = getp(Y[i], y); j > 0; j -= lowbit(j)) {
                chmin(r, val[i][j]);
            }
        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 {
        olist(all(A));
        vector f(3, vector<int>(n + 1));
        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(pt);
        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';
        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: 0
Wrong Answer
time: 0ms
memory: 3508kb

input:

7
1 2 2 0 3 0 3

output:

4
1
5
3

result:

wrong answer 1st lines differ - expected: '4 1 5 3', found: '4'