QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76631#5120. Power of TwoperspectiveTL 492ms9228kbC++238.8kb2023-02-11 04:23:452023-02-11 04:23:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-11 04:23:49]
  • 评测
  • 测评结果:TL
  • 用时:492ms
  • 内存:9228kb
  • [2023-02-11 04:23:45]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP1(i, n) for(ll i = 0; i < (n); i++)
#define REP2(i, a, b) for(ll i = (a); i < (b); i++)
#define REP0(n) for(ll iii = 0; iii < (n); iii++)
#define overload3(a, b, c, name, ...) name
#define rep(...) overload3(__VA_ARGS__, REP2, REP1, REP0)(__VA_ARGS__)
#define si(c) (ll)(c.size())
#define pll pair<ll, ll>

#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define fore(e, v) for(auto &&e : v)

template <typename T, typename S> bool chmax(T &x, const S &y) { return (x < y ? x = y, true : false); }
template <typename T, typename S> bool chmin(T &x, const S &y) { return (x > y ? x = y, true : false); }

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, si(v)) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--) {
        ll n, x, y, z;
        cin >> n >> x >> y >> z;

        vector<ll> c(n);
        fore(e, c) cin >> e;

        ll k = 0;
        vl v(n);
        fore(e, c) v[e]++;
        rep(i, n) k += (!!v[i]);

        string op;
        rep(x) op.push_back('&');
        rep(z) op.push_back('^');
        rep(y) op.push_back('|');

        vl ans;
        if(k == 1 or (x == n) or (y == n) or (z == n)) {
            rep(i, n) ans.emplace_back(c[i]);
        } else if(y + z <= k) {
            for(ll i = n - 1; i >= 0; i--) {
                if(v[i]) { ans.emplace_back(i); }
            }
            for(ll i = n - 1; i >= 0; i--) {
                if(v[i]) rep(v[i] - 1) ans.emplace_back(i);
            }
            reverse(all(ans));
        } else if(!x) {
            int E = 0;
            rep(i, n) if(~v[i] & 1) E++;
            vl lst;
            for(ll i = n - 1; i >= 0; i--) {
                if(y and ~v[i] & 1 and v[i]) {
                    lst.emplace_back(i), v[i]--;
                    y--;
                }
            }
            rep(i, n) rep(v[i]) ans.emplace_back(i);
            fore(e, lst) ans.emplace_back(e);
        } else {
            int E = 0;
            rep(i, n) if(v[i] and ~v[i] & 1) E++;
            vl lst;
            if(x + y <= E) {
                for(ll i = n - 1; i >= 0; i--) {
                    if(ans.size() < (E - x - y) and v[i] and ~v[i] & 1) {
                        ans.emplace_back(i);
                        v[i]--;
                    }
                }
                rep(i, E - x - y) {
                    op[i] = '^';
                    op[x + i] = '&';
                }
                for(ll i = n - 1; i >= 0; i--) {
                    if(ans.size() < E - y and v[i] and ~v[i] & 1) {
                        ans.emplace_back(i);
                        v[i]--;
                    }
                }
                for(ll i = n - 1; i >= 0; i--) {
                    if(lst.size() < y and v[i] and ~v[i] & 1) {
                        lst.emplace_back(i);
                        v[i]--;
                    }
                }
                rep(i, n) rep(v[i]) ans.emplace_back(i);
                fore(e, lst) ans.emplace_back(e);
            } else {
                if(!y) {
                    if(x == 1) {
                        // cout << "here" << endl;

                        rep(i, n) {
                            if(v[i]) {
                                v[i]--;
                                x--;
                                ans.emplace_back(i);
                                break;
                            }
                        }
                        rep(i, n) rep(v[i]) ans.emplace_back(i);
                    } else if((E ^ x) & 1) {
                        swap(op[x], op[0]);
                        x++, z--;

                        int cnt = 0; // 2 個以上
                        rep(i, n) cnt += (v[i] > 1);
                        if(cnt >= 2) {
                            vl used(n);
                            for(ll i = n - 1; i >= 0; i--) {
                                if(v[i] and ~v[i] & 1) ans.emplace_back(i), v[i]--, x--, used[i] = true;
                            }
                            rep(i, n) if(!used[i]) {
                                if(x >= 2 and v[i] >= 2) {
                                    v[i] -= 2, x -= 2;
                                    rep(2) ans.emplace_back(i);
                                }
                            }
                            rep(i, n) while(x >= 2 and v[i] >= 2) {
                                v[i] -= 2, x -= 2;
                                rep(2) ans.emplace_back(i);
                            }
                            rep(i, n) rep(v[i]) ans.emplace_back(i);
                        } else {
                            // cout << "here" << endl;
                            x--;
                            z++;
                            swap(op[x], op[0]);
                            int k = 0;
                            rep(i, n) {
                                if(v[i]) {
                                    k = i;
                                    break;
                                }
                            }

                            if(v[k] > 1) {
                                assert(v[k] >= x);
                                rep(i, x) v[k]--, ans.emplace_back(k), x--;
                                rep(i, n) rep(v[i]) ans.emplace_back(i);
                            } else {
                                ans.emplace_back(k);
                                v[k]--;
                                x--;
                                for(ll i = n - 1; i >= 0; i--) {
                                    if(v[i] and ~v[i] & 1) v[i]--, ans.emplace_back(i), x--;
                                }
                                rep(i, n) while(x >= 2 and v[i] >= 2) {
                                    rep(2) ans.emplace_back(i);
                                    x -= 2, v[i] -= 2;
                                }
                                rep(i, n) rep(v[i]) ans.emplace_back(i);
                            }
                        }
                    } else {
                        for(ll i = n - 1; i >= 0; i--) {
                            if(v[i] and ~v[i] & 1) ans.emplace_back(i), v[i]--, x--;
                        }
                        rep(i, n) {
                            while(v[i] >= 2 and x >= 2) {
                                v[i] -= 2, x -= 2;
                                rep(2) ans.emplace_back(i);
                            }
                        }
                        rep(i, n) rep(v[i]) ans.emplace_back(i);
                    }

                } else {
                    vl lst;
                    for(ll i = n - 1; i >= 0; i--) {
                        if(v[i] and ~v[i] & 1) {
                            ans.emplace_back(i), v[i]--, x--;
                            if(!x) break;
                        }
                    }
                    if(!x) {
                        rep(i, n) {
                            if(v[i] and ~v[i] & 1) { lst.emplace_back(i), v[i]--, y--; }
                        }
                    } else {
                        rep(i, n) {
                            while(v[i] >= 2 and x) {
                                if(x == 1) {
                                    ans.emplace_back(i);
                                    lst.emplace_back(i);
                                    x--, y--;
                                } else {
                                    rep(2) ans.emplace_back(i);
                                    x -= 2;
                                }
                                v[i] -= 2;
                            }
                        }
                        assert(x == 0);
                    }
                    rep(i, n) rep(v[i]) ans.emplace_back(i);
                    fore(e, lst) ans.emplace_back(e);
                }
            }
        }

        map<ll, ll> mp;
        rep(i, n) {
            if(op[i] == '&') {
                if(mp[ans[i]]) {
                    mp = map<ll, ll>();
                    mp[ans[i]] = 1;
                } else {
                    mp = map<ll, ll>();
                }
            }
            if(op[i] == '^') mp[ans[i]] ^= 1;
            if(op[i] == '|') mp[ans[i]] |= 1;
        }

        // {
        //     auto C = c;
        //     sort(all(C));
        //     auto D = ans;
        //     sort(all(D));
        //     assert(C == D);
        // }

        rep(i, n) cout << mp[n - 1 - i];
        cout << endl;
        cout << op << endl;
        rep(i, n) cout << ans[i] << " \n"[i == n - 1];
    }
}

詳細信息

Test #1:

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

input:

4
4 3 0 1
1 0 1 0
4 1 0 3
1 0 1 0
8 0 2 6
1 5 5 7 1 5 5 7
8 0 0 8
1 5 5 7 1 5 5 7

output:

0010
&&&^
0 1 0 1
0011
^&^^
1 0 0 1
10100000
^^^^^^||
1 1 5 5 5 7 7 5
00000000
^^^^^^^^
1 5 5 7 1 5 5 7

result:

ok ok the answer is correct (4 test cases)

Test #2:

score: 0
Accepted
time: 492ms
memory: 9228kb

input:

16
65511 1 1 65509
42389 52308 9452 29149 28980 48173 38152 51625 29991 48293 12319 38611 47245 11954 45410 33185 30976 56806 18986 35564 25430 48493 26311 19090 42172 33403 62406 15847 51266 33712 53139 15610 50006 62298 28716 19191 3057 35733 12331 14483 9604 16610 18534 32110 35673 5239 31310 279...

output:

011100011111111101111001001110101111111101101101011111011100100111011110101110111110111001110100111101110110111100111101101101111110110101011011111111011111110111000110010000010111011100111101111101111111010001010110100100000110101000001011101011001111110011101111010011101101111010101110011101111110...

result:

ok ok the answer is correct (16 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 3400kb

input:

3
1 0 0 1
0
1 0 1 0
0
1 1 0 0
0

output:

1
^
0
1
|
0
0
&
0

result:

ok ok the answer is correct (3 test cases)

Test #4:

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

input:

12
2 0 0 2
0 0
2 0 1 1
0 0
2 0 2 0
0 0
2 1 0 1
0 0
2 1 1 0
0 0
2 2 0 0
0 0
2 0 0 2
0 1
2 0 1 1
0 1
2 0 2 0
0 1
2 1 0 1
0 1
2 1 1 0
0 1
2 2 0 0
0 1

output:

00
^^
0 0
01
^|
0 0
01
||
0 0
01
&^
0 0
01
&|
0 0
00
&&
0 0
11
^^
0 1
11
^|
0 1
11
||
0 1
10
&^
0 1
10
&|
0 1
00
&&
0 1

result:

ok ok the answer is correct (12 test cases)

Test #5:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

40
3 0 0 3
0 0 0
3 0 1 2
0 0 0
3 0 2 1
0 0 0
3 0 3 0
0 0 0
3 1 0 2
0 0 0
3 1 1 1
0 0 0
3 1 2 0
0 0 0
3 2 0 1
0 0 0
3 2 1 0
0 0 0
3 3 0 0
0 0 0
3 0 0 3
0 1 1
3 0 1 2
0 1 1
3 0 2 1
0 1 1
3 0 3 0
0 1 1
3 1 0 2
0 1 1
3 1 1 1
0 1 1
3 1 2 0
0 1 1
3 2 0 1
0 1 1
3 2 1 0
0 1 1
3 3 0 0
0 1 1
3 0 0 3
0 0 1
3 0...

output:

001
^^^
0 0 0
001
^^|
0 0 0
001
^||
0 0 0
001
|||
0 0 0
000
&^^
0 0 0
001
&^|
0 0 0
001
&||
0 0 0
001
&&^
0 0 0
001
&&|
0 0 0
000
&&&
0 0 0
001
^^^
0 1 1
011
^^|
0 1 1
011
^||
0 1 1
011
|||
0 1 1
011
&^^
1 0 1
011
&^|
1 0 1
011
&||
1 0 1
010
&&^
1 0 1
010
&&|
1 0 1
000
&&&
0 1 1
010
^^^
0 0 1
011
^^...

result:

ok ok the answer is correct (40 test cases)

Test #6:

score: 0
Accepted
time: 5ms
memory: 3332kb

input:

120
4 0 0 4
0 0 0 0
4 0 1 3
0 0 0 0
4 0 2 2
0 0 0 0
4 0 3 1
0 0 0 0
4 0 4 0
0 0 0 0
4 1 0 3
0 0 0 0
4 1 1 2
0 0 0 0
4 1 2 1
0 0 0 0
4 1 3 0
0 0 0 0
4 2 0 2
0 0 0 0
4 2 1 1
0 0 0 0
4 2 2 0
0 0 0 0
4 3 0 1
0 0 0 0
4 3 1 0
0 0 0 0
4 4 0 0
0 0 0 0
4 0 0 4
1 1 0 1
4 0 1 3
1 1 0 1
4 0 2 2
1 1 0 1
4 0 3 1
...

output:

0000
^^^^
0 0 0 0
0001
^^^|
0 0 0 0
0001
^^||
0 0 0 0
0001
^|||
0 0 0 0
0001
||||
0 0 0 0
0001
&^^^
0 0 0 0
0001
&^^|
0 0 0 0
0001
&^||
0 0 0 0
0001
&|||
0 0 0 0
0000
&&^^
0 0 0 0
0001
&&^|
0 0 0 0
0001
&&||
0 0 0 0
0001
&&&^
0 0 0 0
0001
&&&|
0 0 0 0
0000
&&&&
0 0 0 0
0011
^^^^
1 1 0 1
0011
^^^|
0 ...

result:

ok ok the answer is correct (120 test cases)

Test #7:

score: 0
Accepted
time: 6ms
memory: 3340kb

input:

336
5 0 0 5
0 0 0 0 0
5 0 1 4
0 0 0 0 0
5 0 2 3
0 0 0 0 0
5 0 3 2
0 0 0 0 0
5 0 4 1
0 0 0 0 0
5 0 5 0
0 0 0 0 0
5 1 0 4
0 0 0 0 0
5 1 1 3
0 0 0 0 0
5 1 2 2
0 0 0 0 0
5 1 3 1
0 0 0 0 0
5 1 4 0
0 0 0 0 0
5 2 0 3
0 0 0 0 0
5 2 1 2
0 0 0 0 0
5 2 2 1
0 0 0 0 0
5 2 3 0
0 0 0 0 0
5 3 0 2
0 0 0 0 0
5 3 1 1
...

output:

00001
^^^^^
0 0 0 0 0
00001
^^^^|
0 0 0 0 0
00001
^^^||
0 0 0 0 0
00001
^^|||
0 0 0 0 0
00001
^||||
0 0 0 0 0
00001
|||||
0 0 0 0 0
00000
&^^^^
0 0 0 0 0
00001
&^^^|
0 0 0 0 0
00001
&^^||
0 0 0 0 0
00001
&^|||
0 0 0 0 0
00001
&||||
0 0 0 0 0
00001
&&^^^
0 0 0 0 0
00001
&&^^|
0 0 0 0 0
00001
&&^||
0 ...

result:

ok ok the answer is correct (336 test cases)

Test #8:

score: 0
Accepted
time: 3ms
memory: 3336kb

input:

896
6 0 0 6
0 0 0 0 0 0
6 0 1 5
0 0 0 0 0 0
6 0 2 4
0 0 0 0 0 0
6 0 3 3
0 0 0 0 0 0
6 0 4 2
0 0 0 0 0 0
6 0 5 1
0 0 0 0 0 0
6 0 6 0
0 0 0 0 0 0
6 1 0 5
0 0 0 0 0 0
6 1 1 4
0 0 0 0 0 0
6 1 2 3
0 0 0 0 0 0
6 1 3 2
0 0 0 0 0 0
6 1 4 1
0 0 0 0 0 0
6 1 5 0
0 0 0 0 0 0
6 2 0 4
0 0 0 0 0 0
6 2 1 3
0 0 0 0 ...

output:

000000
^^^^^^
0 0 0 0 0 0
000001
^^^^^|
0 0 0 0 0 0
000001
^^^^||
0 0 0 0 0 0
000001
^^^|||
0 0 0 0 0 0
000001
^^||||
0 0 0 0 0 0
000001
^|||||
0 0 0 0 0 0
000001
||||||
0 0 0 0 0 0
000001
&^^^^^
0 0 0 0 0 0
000001
&^^^^|
0 0 0 0 0 0
000001
&^^^||
0 0 0 0 0 0
000001
&^^|||
0 0 0 0 0 0
000001
&^||||
...

result:

ok ok the answer is correct (896 test cases)

Test #9:

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

input:

2304
7 0 0 7
0 0 0 0 0 0 0
7 0 1 6
0 0 0 0 0 0 0
7 0 2 5
0 0 0 0 0 0 0
7 0 3 4
0 0 0 0 0 0 0
7 0 4 3
0 0 0 0 0 0 0
7 0 5 2
0 0 0 0 0 0 0
7 0 6 1
0 0 0 0 0 0 0
7 0 7 0
0 0 0 0 0 0 0
7 1 0 6
0 0 0 0 0 0 0
7 1 1 5
0 0 0 0 0 0 0
7 1 2 4
0 0 0 0 0 0 0
7 1 3 3
0 0 0 0 0 0 0
7 1 4 2
0 0 0 0 0 0 0
7 1 5 1
0...

output:

0000001
^^^^^^^
0 0 0 0 0 0 0
0000001
^^^^^^|
0 0 0 0 0 0 0
0000001
^^^^^||
0 0 0 0 0 0 0
0000001
^^^^|||
0 0 0 0 0 0 0
0000001
^^^||||
0 0 0 0 0 0 0
0000001
^^|||||
0 0 0 0 0 0 0
0000001
^||||||
0 0 0 0 0 0 0
0000001
|||||||
0 0 0 0 0 0 0
0000000
&^^^^^^
0 0 0 0 0 0 0
0000001
&^^^^^|
0 0 0 0 0 0 0
...

result:

ok ok the answer is correct (2304 test cases)

Test #10:

score: 0
Accepted
time: 45ms
memory: 3388kb

input:

5760
8 0 0 8
0 0 0 0 0 0 0 0
8 0 1 7
0 0 0 0 0 0 0 0
8 0 2 6
0 0 0 0 0 0 0 0
8 0 3 5
0 0 0 0 0 0 0 0
8 0 4 4
0 0 0 0 0 0 0 0
8 0 5 3
0 0 0 0 0 0 0 0
8 0 6 2
0 0 0 0 0 0 0 0
8 0 7 1
0 0 0 0 0 0 0 0
8 0 8 0
0 0 0 0 0 0 0 0
8 1 0 7
0 0 0 0 0 0 0 0
8 1 1 6
0 0 0 0 0 0 0 0
8 1 2 5
0 0 0 0 0 0 0 0
8 1 3 4...

output:

00000000
^^^^^^^^
0 0 0 0 0 0 0 0
00000001
^^^^^^^|
0 0 0 0 0 0 0 0
00000001
^^^^^^||
0 0 0 0 0 0 0 0
00000001
^^^^^|||
0 0 0 0 0 0 0 0
00000001
^^^^||||
0 0 0 0 0 0 0 0
00000001
^^^|||||
0 0 0 0 0 0 0 0
00000001
^^||||||
0 0 0 0 0 0 0 0
00000001
^|||||||
0 0 0 0 0 0 0 0
00000001
||||||||
0 0 0 0 0 ...

result:

ok ok the answer is correct (5760 test cases)

Test #11:

score: 0
Accepted
time: 116ms
memory: 3324kb

input:

14080
9 0 0 9
0 0 0 0 0 0 0 0 0
9 0 1 8
0 0 0 0 0 0 0 0 0
9 0 2 7
0 0 0 0 0 0 0 0 0
9 0 3 6
0 0 0 0 0 0 0 0 0
9 0 4 5
0 0 0 0 0 0 0 0 0
9 0 5 4
0 0 0 0 0 0 0 0 0
9 0 6 3
0 0 0 0 0 0 0 0 0
9 0 7 2
0 0 0 0 0 0 0 0 0
9 0 8 1
0 0 0 0 0 0 0 0 0
9 0 9 0
0 0 0 0 0 0 0 0 0
9 1 0 8
0 0 0 0 0 0 0 0 0
9 1 1 7
...

output:

000000001
^^^^^^^^^
0 0 0 0 0 0 0 0 0
000000001
^^^^^^^^|
0 0 0 0 0 0 0 0 0
000000001
^^^^^^^||
0 0 0 0 0 0 0 0 0
000000001
^^^^^^|||
0 0 0 0 0 0 0 0 0
000000001
^^^^^||||
0 0 0 0 0 0 0 0 0
000000001
^^^^|||||
0 0 0 0 0 0 0 0 0
000000001
^^^||||||
0 0 0 0 0 0 0 0 0
000000001
^^|||||||
0 0 0 0 0 0 0 ...

result:

ok ok the answer is correct (14080 test cases)

Test #12:

score: 0
Accepted
time: 255ms
memory: 3472kb

input:

33792
10 0 0 10
0 0 0 0 0 0 0 0 0 0
10 0 1 9
0 0 0 0 0 0 0 0 0 0
10 0 2 8
0 0 0 0 0 0 0 0 0 0
10 0 3 7
0 0 0 0 0 0 0 0 0 0
10 0 4 6
0 0 0 0 0 0 0 0 0 0
10 0 5 5
0 0 0 0 0 0 0 0 0 0
10 0 6 4
0 0 0 0 0 0 0 0 0 0
10 0 7 3
0 0 0 0 0 0 0 0 0 0
10 0 8 2
0 0 0 0 0 0 0 0 0 0
10 0 9 1
0 0 0 0 0 0 0 0 0 0
10 ...

output:

0000000000
^^^^^^^^^^
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^^^^^^|
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^^^^^||
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^^^^|||
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^^^||||
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^^|||||
0 0 0 0 0 0 0 0 0 0
0000000001
^^^^||||||
0 0 0 0 0 0 0 0 0 0
000000...

result:

ok ok the answer is correct (33792 test cases)

Test #13:

score: -100
Time Limit Exceeded

input:

65536
16 3 8 5
8 10 13 14 9 12 5 4 13 5 3 14 2 2 5 11
16 4 5 7
2 10 10 4 15 2 14 5 11 12 4 12 5 4 12 11
16 2 0 14
15 3 6 8 5 12 2 2 13 1 4 8 9 1 1 9
16 13 1 2
1 12 9 3 15 10 6 8 13 15 7 12 13 12 3 2
16 2 2 12
3 3 11 10 6 8 6 1 14 2 11 12 2 3 5 2
16 6 3 7
14 12 6 11 7 6 8 13 4 2 4 10 14 4 7 10
16 8 7...

output:

0111111100111100
&&&^^^^^||||||||
14 13 2 2 3 4 5 5 5 8 9 10 11 12 13 14
1101110000110100
&&&&^^^^^^^|||||
11 10 5 2 2 4 4 4 5 10 11 12 12 12 14 15
1011001101111110
^&&^^^^^^^^^^^^^
9 8 2 1 1 1 2 3 4 5 6 8 9 12 13 15
1011000000000000
&&&&&&&&&&&&&^^|
3 12 12 13 15 1 2 3 6 7 8 9 10 12 13 15
010111010...

result: