QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536027#8770. ComparatorRngBasedAC ✓217ms11128kbC++204.5kb2024-08-28 17:44:082024-08-28 17:44:09

Judging History

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

  • [2024-08-28 17:44:09]
  • 评测
  • 测评结果:AC
  • 用时:217ms
  • 内存:11128kb
  • [2024-08-28 17:44:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
int n, k, cond[10][10][2][2], test[10][2][(1 << 10) + 1], U[200015], V[200015], C[200005];
bool ed, argue[200015][2][2];
bitset<1024> f[1024], rf[1024];
vector<int> pos[11][11];
int pri(char c){
    if (c == '(') return 6;
    else if (c == '!') return 1;
    else if (c == '=') return 2;
    else if (c == '&') return 3;
    else if (c == '|') return 4;
    else return 5;
}
bool solve(string s, bool b1, bool b2){
    s = '(' + s + ')';
    vector<char> res, st;
    for (auto i : s){
        if (i == '(')
            st.emplace_back(i);
        else if (i == ')'){
            while (st.back() != '(')
                res.emplace_back(st.back()), st.pop_back();
            st.pop_back();
            while (!st.empty() && st.back() == '!')
                res.emplace_back(st.back()), st.pop_back();
        }
        else if (i == '!' || i == '=' || i == '^' || i == '&' || i == '|'){
            while (pri(st.back()) < pri(i))
                res.emplace_back(st.back()), st.pop_back();
            st.emplace_back(i);
        }
        else {
            if (i == '0' || i == '1')
                res.emplace_back(i);
            else if (i == 'x')
                res.emplace_back('0' + b1);
            else res.emplace_back('0' + b2);
            while (!st.empty() && st.back() == '!')
                res.emplace_back(st.back()), st.pop_back();
        }
    }
    vector<int> cnt;
    for (auto i : res){
        if (i == '0' || i == '1')
            cnt.emplace_back(i - '0');
        else if (i == '!')
            assert(cnt.size() >= 1), cnt.back() ^= 1;
        else {
            assert(cnt.size() >= 2);
            int c1 = cnt.back(); cnt.pop_back();
            int c2 = cnt.back(); cnt.pop_back();
            if (i == '=')
                cnt.emplace_back(c1 == c2);
            if (i == '&')
                cnt.emplace_back(c1 & c2);
            if (i == '|')
                cnt.emplace_back(c1 | c2);
            if (i == '^')
                cnt.emplace_back(c1 ^ c2);
        }
    }
    assert(cnt.size() == 1);
    return cnt.back();
}
// int checker(int a, int b){
//     for (int i = 1; i <= n; i++){
//         if (argue[i][a >> U[i] & 1][b >> V[i] & 1])
//             return i;
//     }
//     return n + 1;
// }
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        int u, v, c;
        string s;
        cin >> u >> v >> s >> c;
        u--; v--;
        pos[u][v].emplace_back(i);
        U[i] = u, V[i] = v, C[i] = c;
        for (int j = 0; j <= 1; j++)
            for (int h = 0; h <= 1; h++)
                argue[i][j][h] = solve(s, j, h);
    }
    cin >> ed;
    C[n + 1] = argue[n + 1][0][0] = argue[n + 1][0][1] = argue[n + 1][1][0] = argue[n + 1][1][1] = ed;
    for (int i = 0; i < k; i++){
        for (int j = 0; j < k; j++){
            for (int x = 0; x <= 1; x++){
                for (int y = 0; y <= 1; y++){
                    cond[i][j][x][y] = n + 1;
                    for (auto h : pos[i][j]){
                        if (argue[h][x][y]){
                            cond[i][j][x][y] = h;
                            break;
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < k; i++){
        for (int x = 0; x <= 1; x++){
            for (int j = 0; j < (1 << k); j++){
                test[i][x][j] = n + 1;
                for (int l = 0; l < k; l++)
                    test[i][x][j] = min(test[i][x][j], cond[i][l][x][(j >> l) & 1]);
            }
        }
    }
    for (int i = 0; i < (1 << k); i++){
        for (int j = 0; j < (1 << k); j++){
            int stop = n + 1;
            for (int l = 0; l < k; l++)
                stop = min(stop, test[l][i >> l & 1][j]);
            f[i][j] = rf[j][i] = C[stop];
        }
    }
    ll ans1 = 0, ans2 = 0, ans3 = 0;
    for (int i = 0; i < (1 << k); i++){
        ans1 += (f[i][i] != 0);
        for (int j = 0; j < (1 << k); j++){
            ans2 += (f[i][j] == 1 && f[j][i] == 1);
            if (f[i][j] == 0)
                ans3 += (f[i] & rf[j]).count();
        }
    }
    cout << ans1 << " " << ans2 << " " << ans3 << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 44ms
memory: 3828kb

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: 188ms
memory: 7408kb

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: 34ms
memory: 11128kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5684kb

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

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

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

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: 75ms
memory: 4316kb

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

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: 3ms
memory: 6088kb

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 217ms
memory: 7572kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'