QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429904#8770. Comparatorskittles1412#AC ✓237ms9048kbC++1711.2kb2024-06-03 02:28:532024-06-03 02:28:55

Judging History

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

  • [2024-06-03 02:28:55]
  • 评测
  • 测评结果:AC
  • 用时:237ms
  • 内存:9048kb
  • [2024-06-03 02:28:53]
  • 提交

answer

// cf bits/extc++.h nonsense
#ifdef ONLINE_JUDGE
#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#endif

#line 1 "c.cpp"
// 69683a8183e36171b0123a3fbef815656276c8d9
#include "bits/extc++.h"
#line 1 "/home/skittles1412/workspace/cp/library/template.hpp"



#line 5 "/home/skittles1412/workspace/cp/library/template.hpp"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

using u32 = uint32_t;
using u64 = uint64_t;
using ld = long double;

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))


#line 1 "/home/skittles1412/workspace/cp/library/utils.hpp"



#line 5 "/home/skittles1412/workspace/cp/library/utils.hpp"

template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
    out << "[";
    for (int i = 0; i < sz(arr); i++) {
        if (i) {
            out << ", ";
        }
        out << arr[i];
    }
    return out << "]";
}

template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& arr) {
    out << "[";
    for (size_t i = 0; i < N; i++) {
        if (i) {
            out << ", ";
        }
        out << arr[i];
    }
    return out << "]";
}

template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}

/**
 * Computes the first x in [l, r) such that cb(x) is true.
 *
 * If no x in that range is true, returns r
 */
template <typename T, typename Cb>
T first_true(T l, T r, const Cb& cb) {
    while (l < r) {
        T mid = (l + r) / 2;
        if (cb(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

/**
 * Computes the last x in (l, r] such that cb(x) is true.
 *
 * If no x in that range is true, returns l
 */
template <typename T, typename Cb>
T last_true(T l, T r, const Cb& cb) {
    while (l < r) {
        T mid = (l + r + 1) / 2;
        if (cb(mid)) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }
    return l;
}

template <typename T>
T reversed(T arr) {
    reverse(begin(arr), end(arr));
    return arr;
}

template <typename T>
bool is_palin(const T& arr) {
    return arr == reversed(arr);
}

template <typename T>
T sorted(T arr) {
    sort(begin(arr), end(arr));
    return arr;
}

template <typename T>
T negated(T arr) {
    for (auto& a : arr) {
        a = -a;
    }
    return arr;
}

template <typename T, bool STRICT>
vector<int> comp_prev_helper(const vector<T>& arr) {
    int n = sz(arr);

    vector<int> ans(n);

    vector<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        auto cmp = [&]() -> bool {
            if constexpr (STRICT) {
                return st.back().first <= arr[i];
            } else {
                return st.back().first < arr[i];
            }
        };
        while (sz(st) && cmp()) {
            st.pop_back();
        }

        if (sz(st)) {
            ans[i] = st.back().second;
        } else {
            ans[i] = -1;
        }
        st.emplace_back(arr[i], i);
    }

    return ans;
}

/**
 * Computes ans[i], the closest index j to the left of i where arr[j] > arr[i]
 *
 * ans[i] = -1 if no such j exists
 */
template <typename T>
vector<int> comp_prev_gt(const vector<T>& arr) {
    return comp_prev_helper<T, true>(arr);
}

/**
 * Computes ans[i], the closest index j to the left of i where arr[j] >= arr[i]
 *
 * ans[i] = -1 if no such j exists
 */
template <typename T>
vector<int> comp_prev_ge(const vector<T>& arr) {
    return comp_prev_helper<T, false>(arr);
}

/**
 * reverses an array of indices
 *
 * specifically, it reverses the array and computes arr[i] = n - 1 - arr[i]
 */
vector<int> reverse_indices(vector<int> arr) {
    int n = sz(arr);

    reverse(begin(arr), end(arr));
    for (auto& a : arr) {
        a = n - 1 - a;
    }

    return arr;
}

/**
 * Computes ans[i], the closest index j to the right of i where arr[j] > arr[i]
 *
 * ans[i] = n if no such j exists
 */
template <typename T>
vector<int> comp_next_gt(vector<T> arr) {
    reverse(begin(arr), end(arr));

    return reverse_indices(comp_prev_gt(arr));
}

/**
 * Computes ans[i], the closest index j to the right of i where arr[j] >= arr[i]
 *
 * ans[i] = n if no such j exists
 */
template <typename T>
vector<int> comp_next_ge(vector<T> arr) {
    reverse(begin(arr), end(arr));

    return reverse_indices(comp_prev_ge(arr));
}

template <typename Cb>
struct CmpByKey {
    Cb cb;

    explicit CmpByKey(const Cb& cb) : cb(cb) {}

    template <typename T>
    bool operator()(const T& a, const T& b) const {
        return cb(a) < cb(b);
    }
};

/**
 * outputs will be in the range [0, m), returns m
 */
int coord_comp(const vector<int*>& arr) {
    vector<int> vals;
    for (auto& a : arr) {
        vals.push_back(*a);
    }

    sort(begin(vals), end(vals));
    vals.erase(unique(begin(vals), end(vals)), end(vals));

    for (auto& a : arr) {
        *a = int(lower_bound(begin(vals), end(vals), *a) - begin(vals));
    }

    return sz(vals);
}

/**
 * outputs will be in the range [0, m), returns {m, result}
 */
template <typename T>
pair<int, vector<int>> coord_comp(const vector<T>& arr) {
    vector<T> vals = arr;
    sort(begin(vals), end(vals));
    vals.erase(unique(begin(vals), end(vals)), end(vals));

    vector<int> ans;
    for (auto& a : arr) {
        ans.push_back(
            int(lower_bound(begin(vals), end(vals), a) - begin(vals)));
    }

    return {sz(vals), ans};
}

template <typename T>
bool on(T mask, int bit) {
    return (mask >> bit) & 1;
}


#line 5 "c.cpp"

struct Paren {
    int n;
    vector<pair<int, int>> parens;
    vector<int> paren_id;

    Paren(const string& s) : n(sz(s)), paren_id(n, -1) {
        vector<int> st;
        for (int i = 0; i < n; i++) {
            if (s[i] == '(') {
                st.push_back(paren_id[i] = sz(parens));
                parens.emplace_back(i, -1);
            } else if (s[i] == ')') {
                parens[paren_id[i] = st.back()].second = i;
                st.pop_back();
            }
        }
    }

    int rparen_for(int ind) const {
        return parens[paren_id[ind]].second;
    }

    int lparen_for(int ind) const {
        return parens[paren_id[ind]].first;
    }
};

// ^ then | then & then = then ! then ()
struct Eval {
    string s;
    const Paren& p;
    int x, y;

    Eval(const string& s, const Paren& p, int x, int y)
        : s(s), p(p), x(x), y(y) {}

    int eval(int l, int r) const {
        while (s[l] == '(' && p.rparen_for(l) == r) {
            l++;
            r--;
        }

        if (l == r) {
            if (s[l] == 'x') {
                return x;
            } else if (s[l] == 'y') {
                return y;
            } else if (s[l] == '0') {
                return 0;
            } else if (s[l] == '1') {
                return 1;
            }
            assert(false);
        }

        return eval_xor(l, r);
    }

    template <typename Cb>
    void parse_binop(int l, int r, char op, const Cb& cb) const {
        int i = l, cl = i;
        while (i <= r) {
            if (s[i] == '(') {
                i = p.rparen_for(i) + 1;
            } else if (s[i] == op) {
                cb(cl, i - 1);
                i++;
                cl = i;
            } else {
                i++;
            }
        }

        cb(cl, r);
    }

    int eval_xor(int l, int r) const {
        int ans = 0;

        parse_binop(l, r, '^', [&](int ql, int qr) -> void {
            ans ^= eval_or(ql, qr);
        });

        return ans;
    }

    int eval_or(int l, int r) const {
        int ans = 0;

        parse_binop(l, r, '|', [&](int ql, int qr) -> void {
            ans |= eval_and(ql, qr);
        });

        return ans;
    }

    int eval_and(int l, int r) const {
        int ans = 1;

        parse_binop(l, r, '&', [&](int ql, int qr) -> void {
            ans &= eval_eq(ql, qr);
        });

        return ans;
    }

    int eval_eq(int l, int r) const {
        int ans = 1;

        parse_binop(l, r, '=', [&](int ql, int qr) -> void {
            ans = ans == eval_neg(ql, qr);
        });

        return ans;
    }

    int eval_neg(int l, int r) const {
        int neg = 0, i = l;

        while (s[i] == '!') {
            neg ^= 1;
            i++;
        }

        return neg ^ eval(i, r);
    }

    int eval() const {
        return eval(0, sz(s) - 1);
    }
};

using B = bitset<1024>;

void solve() {
    int n, m;
    cin >> n >> m;

    int ret_val[n], arr[m][m][2][2];
    memset(arr, 0x3f, sizeof(arr));
    for (int i = 0; i < n; i++) {
        int ind1, ind2;
        string expr;
        cin >> ind1 >> ind2 >> expr >> ret_val[i];
        ind1--;
        ind2--;

        Paren p(expr);
        for (int x : {0, 1}) {
            for (int y : {0, 1}) {
                if (Eval(expr, p, x, y).eval()) {
                    arr[ind1][ind2][x][y] = min(arr[ind1][ind2][x][y], i);
                }
            }
        }
    }

    int def_return;
    cin >> def_return;

    B graph[1 << m] {};
    for (int m1 = 0; m1 < (1 << m); m1++) {
        for (int m2 = 0; m2 < (1 << m); m2++) {
            int res = n;

            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    res = min(res, arr[i][j][on(m1, i)][on(m2, j)]);
                }
            }

            if (res == n) {
                graph[m1][m2] = def_return;
            } else {
                graph[m1][m2] = ret_val[res];
            }
        }
    }

    int ans1 = 0, ans2 = 0, ans3 = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        if (graph[mask][mask]) {
            ans1++;
        }
    }
    for (int m1 = 0; m1 < (1 << m); m1++) {
        for (int m2 = 0; m2 < (1 << m); m2++) {
            if (graph[m1][m2] && graph[m2][m1]) {
                ans2++;
            }
        }
    }

    for (int m1 = 0; m1 < (1 << m); m1++) {
        auto ng = ~graph[m1];

        for (int m2 = 0; m2 < (1 << m); m2++) {
            if (graph[m1][m2]) {
                ans3 += (graph[m2] & ng).count();
            }
            // for (int m3 = 0; m3 < (1 << m); m3++) {
            //     if (graph[m1][m2] && graph[m2][m3] && !graph[m1][m3]) {
            //         ans3++;
            //     }
            // }
        }
    }

    cout << ans1 << " " << ans2 << " " << ans3 << endl;
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

3 2
1 1 (x=0)&(y=1) 1
1 1 (x=1)&(y=(x^x)) 0
2 2 (x=1)|(y=0) 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

4 3
2 1 x=0&(y=1) 1
1 2 !x^!!y 0
2 3 ((x|1)=y)&1&1 1
3 1 !x&!x&!x 0
1

output:

3 25 52

result:

ok single line: '3 25 52'

Test #3:

score: 0
Accepted
time: 38ms
memory: 3692kb

input:

1413 3
1 3 0 0
3 3 !x 0
2 2 x=0 1
1 2 !y^0 1
2 3 (x^1) 0
3 2 ((!0)) 1
1 1 !!1=(y) 0
2 2 !(1^x)&y 1
3 2 (y)&1|!!1 0
3 1 !x=(y&y=y) 0
2 1 (((!1)^!x)) 1
2 3 !0=(0&y)=1&y 0
1 2 ((((!0)))|!1) 0
3 1 !(y=!1=x|(!x)) 0
1 1 ((((y=!y)))&!0) 0
2 3 ((y=1)^!1^!!1|0) 1
2 3 1|(!x)&!x|1|(x=1) 1
2 3 !0^!!!!y&0=(!1&!0...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #4:

score: 0
Accepted
time: 237ms
memory: 4440kb

input:

181737 10
5 2 1 1
1 10 !1=!x 0
10 1 (1^x) 0
2 4 !1 1
10 8 y=(!1)^1 1
6 2 !((x&!x)) 1
1 10 !!((!x)|x) 1
7 10 (((0))) 0
7 3 !(1)^!x 0
10 4 (!1)&x 0
7 7 !y&!0 1
8 8 !1=(x)|1^1 1
2 6 ((!!!x)) 0
7 2 1 1
2 2 y=1=0 0
6 3 (!0) 0
6 4 0 0
1 1 (!1) 1
1 8 y 1
3 5 !x|!x^!1 0
4 7 (!0) 0
3 4 !1&1&!1|!0 1
2 7 ((0|1...

output:

1024 1048576 0

result:

ok single line: '1024 1048576 0'

Test #5:

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

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

1 1
1 1 x^y|1 0
1

output:

1 1 0

result:

ok single line: '1 1 0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1 1
1 1 x&y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

1 1
1 1 x=y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

2 2
1 2 !x&!y 1
1 1 !x&y 0
1

output:

4 12 2

result:

ok single line: '4 12 2'

Test #10:

score: 0
Accepted
time: 115ms
memory: 3844kb

input:

2 10
9 8 ((((!((!x=1))^(!1&(x|x|!y))&((!y&!x=(x=y)))&!((((x=1))&(0=(y))^(!!(!!x^1=x)&(x)^y&1=!x&1=(((!0^(1)^1))^!(((((y))|x|!y))))^!!0=!y&(0)|(y=x&!y&y=x)))=((((!!y&!!0|!0^!0)=!x))))^0&(((!1=!(!x)))|(((((x=1|!y|y)=(!1^1^0^(0)))=!0^1)))=(!(!1^(((((!1)^!x^0))))=(1)^((((y=((x))|(0)|(!1^1)))|(!!!y))=((!...

output:

0 0 0

result:

ok single line: '0 0 0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

4 3
1 1 !!!!!!x 0
2 1 !!y 1
1 2 !!!!!x 1
2 2 !!!x 0
1

output:

4 16 0

result:

ok single line: '4 16 0'

Test #12:

score: 0
Accepted
time: 0ms
memory: 5440kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 183ms
memory: 4432kb

input:

200000 10
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10...

output:

512 262144 134217728

result:

ok single line: '512 262144 134217728'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

10 3
3 1 (!x) 1
3 2 !1&x&1&!y 1
2 1 ((x)&y) 1
1 3 0 0
2 2 !1&0=y&0 1
3 3 (!y)^y 1
2 1 0|((!y)) 0
3 2 x 0
2 2 (y|1^x) 0
2 1 ((!0)|y) 0
1

output:

8 64 0

result:

ok single line: '8 64 0'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'