QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323249#147. Floppyduongnc0000 30ms9164kbC++203.7kb2024-02-09 00:28:262024-02-09 00:28:28

Judging History

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

  • [2024-02-09 00:28:28]
  • 评测
  • 测评结果:0
  • 用时:30ms
  • 内存:9164kb
  • [2024-02-09 00:28:26]
  • 提交

floppy

#include<bits/stdc++.h>
#include "floppy.h"

using namespace std;

template<class T, class F>
struct sparse_table{
    int n;
    vector<vector<T>> data;
    F TT;
    T T_id;
    sparse_table(){ }
    // O(n log n)
    sparse_table(const vector<T> &a, F TT, T T_id): n((int)a.size()), TT(TT), T_id(T_id), data({a}){
        for(auto p = 1, i = 1; p << 1 <= n; p <<= 1, ++ i){
            data.emplace_back(n - (p << 1) + 1);
            for(auto j = 0; j < (int)data[i].size(); ++ j) data[i][j] = TT(data[i - 1][j], data[i - 1][j + p]);
        }
    }
    // O(1)
    T query(int l, int r) const{
        assert(0 <= l && l <= r && r <= n);
        if(l == r) return T_id;
        int d = __lg(r - l);
        return TT(data[d][l], data[d][r - (1 << d)]);
    }
};

pair<int, int> op(pair<int, int> a, pair<int, int> b) { return max(a, b); }

void read_array(int subtask_id, const std::vector<int> &v) {
    int n = (int)(v.size());
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) a[i] = {v[i], i};
    sparse_table st(a, op, pair{0, 0});

    vector<vector<int>> G(n);
    auto dfs = [&](auto self, int l, int r) -> int {
        if (l == r) return ~l;
        int pos = st.query(l, r).second;
        G[pos].emplace_back(self(self, l, pos));
        G[pos].emplace_back(self(self, pos + 1, r));
        return pos;
    };
    int root = dfs(dfs, 0, n);
    auto dfs2 = [&](auto self, int v) -> pair<int, string> {
        vector<pair<int, string>> vec;
        for (int u : G[v]) {
            if (u < 0) vec.emplace_back(u, "");
            else vec.push_back(self(self, u));
        }
        sort(vec.rbegin(), vec.rend());
        if (vec[0].second.empty() and vec[1].second.empty()) return {vec[0].first, "01"};
        if (vec[0].second.empty()) return {vec[0].first, "0" + vec[1].second + "1"};
        if (vec[1].second.empty()) return {vec[0].first, vec[0].second + "01"};
        return {vec[0].first, vec[0].second + "0" + vec[1].second + "1"};
    };
    save_to_floppy(dfs2(dfs2, root).second);
}

std::vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) {
    int n = (int)(bits.size()) / 2;
    vector<pair<int, int>> aa(n);
    for (int i = 0; i < n; ++i) aa[i].second = i;
    // cerr << bits << endl;
    auto dfs = [&](auto self, int posl, int posr, int l, int r, int l1, int r1) -> void {
        // cout << "dfs: " << posl << " " << posr << " " << l << " " << r << " " << l1 << " " << r1 << endl;
        int len = posr - posl + 1, sum = 0, pos = -1;
        if (len == 2) {
            aa[l].first = r1;
            return;
        }
        for (int i = posr; i >= posl; --i) {
            sum += (bits[i] == '1' ? 1 : -1);
            if (sum == 0) {
                pos = i;
                break;
            }
        }
        assert(pos != -1);
        if (pos == posl) {
            aa[l].first = r1;
            self(self, posl + 1, posr - 1, l + 1, r, l1, r1 - 1);
        }
        else if (pos == posr - 1) {
            aa[r].first = r1;
            self(self, posl, posr - 2, l, r - 1, l1, r1 - 1);
        }
        else {
            int inter = l + (pos - posl) / 2;
            aa[inter].first = r1;
            self(self, posl, pos - 1, l, inter - 1, l1, l1 + pos / 2 - 1);
            self(self, pos + 1, posr - 1, inter + 1, r, l1 + pos / 2, r1 - 1);
        }
    };
    dfs(dfs, 0, 2 * n - 1, 0, n - 1, 0, n - 1);
    sparse_table st(aa, op, pair{0, 0});
    vector<int> answers((int)(a.size()));
    for (int i = 0; i < (int)(a.size()); ++i) {
        answers[i] = st.query(a[i], b[i] + 1).second;
    }
    return answers;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3804kb

input:

1 496
484
491
478
483
452
446
458
493
453
457
468
418
440
241
267
365
462
441
495
39
54
70
26
97
152
24
105
85
170
298
42
275
305
295
297
207
211
296
184
346
98
123
171
157
135
194
243
156
115
196
169
53
138
93
263
251
201
195
333
324
396
338
270
311
359
289
290
486
403
183
339
310
473
464
471
469
4...

output:

992
01001000110111001010010010101100111100101001101001001110100101100100101001111001010001110100011000100111110000111100111000101100101110001001110010011100100011101001001100010100111111000011101010011001111001001100100110011001011110000101100010011111001000100001111100001011110010010101100001101011...

input:

1 496
992
01001000110111001010010010101100111100101001101001001110100101100100101001111001010001110100011000100111110000111100111000101100101110001001110010011100100011101001001100010100111111000011101010011001111001001100100110011001011110000101100010011111001000100001111100001011110010010101100001...

output:

171
330
330
275
171
330
319
419
267
419
478
419
483
171
419
369
483
478
418
330
171
171
419
275
419
469
330
51
84
145
158
419
330
413
462
419
128
356
84
419
171
469
419
453
330
51
163
330
330
275
275
462
419
247
171
146
330
275
483
483
330
330
171
171
330
419
275
419
419
483
134
171
275
397
369
462
...

result:

wrong answer wrong answer on query #1 (a = 109, b = 205): read 171 but expected 115

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 10ms
memory: 4792kb

input:

2 9998
941669562
945620824
923950848
951745929
487936934
545172907
544098433
249251812
620978276
575815248
584717207
588068187
353162497
679201670
592738155
438327774
762119945
576801563
408534366
592715009
525377786
603981493
-93758897
137509462
-38676966
-36724784
654920761
-595506762
-645387884
-...

output:

19996
010011001000111001010011100011100011001100100101110001101010101000111000011100110001001100011111001001111001010011000010001111111001001100110100101010001011001100100011101011001001100011001110001111111110010001011001010001101000110000110111100101100001101101100100010110101100111000101001110000...

input:

2 9998
19996
01001100100011100101001110001110001100110010010111000110101010100011100001110011000100110001111100100111100101001100001000111111100100110011010010101000101100110010001110101100100110001100111000111111111001000101100101000110100011000011011110010110000110110110010001011010110011100010100...

output:

6831
8096
4724
4724
8096
5587
4724
2387
7332
7332
3121
6586
3582
8096
7726
4724
8096
1789
8096
7332
2643
6831
4724
5587
6831
8096
1196
7332
8096
6744
8096
8096
8096
3899
7820
8096
8096
8096
4724
4724
8096
8096
8096
8096
8096
4724
8096
8096
6238
6586
8096
3411
8096
2041
8096
2440
8096
9932
7197
7281
...

result:

wrong answer wrong answer on query #1 (a = 2131, b = 6955): read 6831 but expected 6131

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 30ms
memory: 9164kb

input:

3 39995
922975946
766568552
929754744
983095922
988967630
879723897
928174186
951250463
831467029
836738151
464712826
467214506
167661408
156498284
426000721
530835328
-35115993
-86200136
327603078
448684869
192895652
125768327
402822176
196767853
409109378
985776352
976681898
967347754
989156210
99...

output:

79990
001101010010100100100011011000110100011001101111100011110100101001101100000111100100111001000100111001001011011001111000010101011001011100100100110011000010101011111100100011000110110001101100101001011100101010100110010010111100010110010100001000111111110100101111100100100101100010110111001000...

input:

3 39995
79990
0011010100101001001000110110001101000110011011111000111101001010011011000001111001001110010001001110010010110110011110000101010110010111001001001100110000101010111111001000110001101100011011001010010111001010101001100100101111000101100101000010001111111101001011111001001001011000101101...

output:

12305
13752
36748
30336
16782
13752
10326
30336
30336
26608
20499
20499
36748
16782
37879
36748
30336
9657
16782
20499
36299
33971
20499
20499
17235
12305
34918
34918
20499
36748
20499
13752
20499
20499
20499
36748
20499
30336
9155
20499
18549
20499
3023
33971
13752
34918
30336
18549
5986
26608
3916...

result:

wrong answer wrong answer on query #1 (a = 9100, b = 12589): read 12305 but expected 11215