QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253906#5543. The Only Modewarner1129Compile Error//C++203.9kb2023-11-17 19:36:182023-11-17 19:36:20

Judging History

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

  • [2023-11-17 19:36:20]
  • 评测
  • [2023-11-17 19:36:18]
  • 提交

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

#define unordered_map __gnu_pbds::gp_hash_table;

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

answer.code:47:23: error: ‘auto’ can only be specified for variables or function declarations
   47 | #define unordered_map __gnu_pbds::gp_hash_table;
      |                       ^~~~~~~~~~
answer.code:47:23: note: in definition of macro ‘unordered_map’
   47 | #define unordered_map __gnu_pbds::gp_hash_table;
      |                       ^~~~~~~~~~
answer.code:49:14: error: expected unqualified-id before ‘<’ token
   49 | unordered_map<int, unordered_map<int, int>> val;
      |              ^
answer.code:49:33: error: expected unqualified-id before ‘<’ token
   49 | unordered_map<int, unordered_map<int, int>> val;
      |                                 ^
answer.code: In constructor ‘BIT2D::BIT2D()’:
answer.code:53:9: error: ‘val’ was not declared in this scope
   53 |         val.clear();
      |         ^~~
answer.code: In member function ‘void BIT2D::add(int, int, int)’:
answer.code:59:31: error: ‘val’ was not declared in this scope
   59 |                 if (auto it = val[i].find(j); it != val[i].end())
      |                               ^~~
answer.code: In member function ‘int BIT2D::qry(int, int)’:
answer.code:65:53: error: ‘val’ was not declared in this scope
   65 |         for (int i = x; i > 0; i -= lowbit(i)) if (!val[i].empty())
      |                                                     ^~~