QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323250#147. Floppyduongnc00028 86ms9244kbC++203.7kb2024-02-09 00:33:082024-02-09 00:33:09

Judging History

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

  • [2024-02-09 00:33:09]
  • 评测
  • 测评结果:28
  • 用时:86ms
  • 内存:9244kb
  • [2024-02-09 00:33:08]
  • 提交

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 - posl) / 2 - 1);
            self(self, pos + 1, posr - 1, inter + 1, r, l1 + (pos - posl) / 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: 7
Accepted

Test #1:

score: 7
Accepted
time: 2ms
memory: 3836kb

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:

115
18
115
305
115
18
305
373
115
305
115
373
115
115
305
365
373
461
305
305
18
115
429
201
305
305
115
39
67
18
115
115
305
305
115
373
115
352
67
305
115
373
115
453
18
67
18
305
373
115
115
429
373
252
115
125
115
201
115
491
115
305
115
18
305
305
287
305
115
305
18
201
115
373
370
305
305
201
...

result:

ok good job! L = 992

Test #2:

score: 7
Accepted
time: 2ms
memory: 3836kb

input:

1 496
466
469
320
402
391
453
73
101
122
49
54
94
93
148
197
168
233
144
125
161
69
34
247
76
37
90
71
33
42
212
188
156
110
135
165
374
277
289
248
273
236
131
210
242
238
231
366
346
314
358
300
349
322
412
315
268
354
340
99
176
290
313
221
229
332
265
269
146
316
403
369
492
190
256
266
100
126
...

output:

992
01001001100101001010011101001100011000111100011000101110000101101111001001000101100011111000110010011111000110001010100101100100110111100111110010100101010010110110010010111000011100110101001010111000111000001100111111000011100110010010101110001001001011011000011001110110001011110010101011100101...

input:

1 496
992
01001001100101001010011101001100011000111100011000101110000101101111001001000101100011111000110010011111000110001010100101100100110111100111110010100101010010110110010010111000011100110101001010111000111000001100111111000011100110010010101110001001001011011000011001110110001011110010101011...

output:

339
339
339
389
222
339
256
256
339
180
339
339
339
310
109
71
339
365
256
256
171
455
484
264
200
339
256
413
339
339
339
339
339
339
109
339
256
109
339
222
339
339
109
339
109
339
455
346
109
213
339
53
339
339
109
339
339
339
109
339
339
339
339
339
339
109
109
339
256
109
339
256
310
109
339
10...

result:

ok good job! L = 992

Test #3:

score: 7
Accepted
time: 2ms
memory: 3796kb

input:

1 496
487
495
488
494
486
493
490
492
485
491
483
489
484
482
480
481
479
478
477
475
476
473
474
472
470
471
466
469
468
465
467
464
462
463
458
461
459
460
457
456
455
454
453
451
452
449
450
448
447
444
446
445
442
443
441
434
440
438
439
437
435
436
433
431
432
429
430
424
428
423
427
426
422
42...

output:

992
01001001001001001000010000010010001001000100010010010000000100100001000100010010001000100100100100010000010010010010001001001000100001001001001000100100100010010001001001000010010000100010010010010010000010010010000100000100100010010010001000010000100010000100000100010000010000000100100100010010...

input:

1 496
992
01001001001001001000010000010010001001000100010010010000000100100001000100010010001000100100100100010000010010010010001001001000100001001001001000100100100010010001001001000010010000100010010010010010000010010010000100000100100010010010001000010000100010000100000100010000010000000100100100...

output:

157
202
218
223
145
242
85
315
70
15
230
197
261
162
175
175
25
112
225
98
68
319
290
147
247
167
353
360
167
3
22
315
432
353
5
418
313
151
129
58
54
206
151
18
125
227
112
92
73
98
27
91
153
318
400
16
121
234
174
78
244
68
372
242
48
11
5
221
129
194
395
33
263
102
91
172
391
125
112
240
266
349
...

result:

ok good job! L = 992

Test #4:

score: 7
Accepted
time: 0ms
memory: 4104kb

input:

1 495
473
486
488
489
491
485
477
474
472
480
483
460
459
462
448
447
444
449
454
442
434
437
443
439
433
430
440
438
435
431
429
436
424
421
426
418
422
417
413
416
414
405
409
406
407
403
404
391
392
385
388
387
386
390
384
377
369
382
371
375
374
370
367
368
366
360
362
363
364
352
348
361
354
35...

output:

990
01010101000001110100011000011101000101100001110000011100011001000100010010010010010001110000110010000100010101000110000111001001001001010010100100010100011001100100011000011001100011010001010001100010010100001110000010100011001001100101010001001010000010011100000111000101101001010010010001100100...

input:

1 495
990
01010101000001110100011000011101000101100001110000011100011001000100010010010010010001110000110010000100010101000110000111001001001001010010100100010100011001100100011000011001100011010001010001100010010100001110000010100011001001100101010001001010000010011100000111000101101001010010010001...

output:

290
457
363
400
302
348
463
117
103
109
363
385
53
457
130
13
18
53
126
18
81
446
482
81
409
491
123
18
377
486
277
13
342
98
342
298
486
456
438
361
13
46
382
18
347
293
431
457
44
482
483
75
412
369
483
13
428
483
382
299
430
363
98
486
109
478
306
281
31
331
461
182
446
46
205
87
340
317
356
53
6...

result:

ok good job! L = 990

Test #5:

score: 7
Accepted
time: 2ms
memory: 4068kb

input:

1 498
379
228
234
288
275
306
283
287
302
280
196
162
261
251
312
255
204
405
289
220
265
269
342
148
231
338
296
394
161
267
340
116
218
226
305
186
282
240
391
337
351
366
401
321
333
454
362
396
406
329
380
443
190
292
301
273
358
377
402
398
418
414
450
475
348
354
419
285
291
279
216
262
349
32...

output:

996
00101001100101000011001111100011110001010110010100111001010010101001001111001010111001011100101001011001010011010100110011101100101001000101110011001110011000110010110010110001001010111000101010101011110001010010111001000101111000111000011010001001101100010110010110011111001010101001000111100001...

input:

1 498
996
00101001100101000011001111100011110001010110010100111001010010101001001111001010111001011100101001011001010011010100110011101100101001000101110011001110011000110010110010110001001010111000101010101011110001010010111001000101111000111000011010001001101100010110010110011111001010101001000111...

output:

417
63
362
63
456
372
102
372
63
237
372
289
63
63
372
289
63
102
63
63
63
372
63
63
78
289
162
102
162
289
289
63
372
102
372
63
115
102
372
372
372
138
162
372
372
372
289
372
118
289
372
280
162
63
372
102
372
289
289
372
372
372
362
417
63
372
474
289
63
78
372
268
237
417
372
417
351
63
417
237...

result:

ok good job! L = 996

Subtask #2:

score: 21
Accepted

Test #6:

score: 21
Accepted
time: 10ms
memory: 4824kb

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:

6131
6131
359
6131
6131
6131
6131
359
6131
6131
2817
6131
359
6131
6131
5102
6131
1055
6131
7338
2817
6131
5760
5760
6131
6131
359
6131
6131
6664
6131
7884
6131
2817
7338
7338
8312
6131
6131
5102
6131
7338
6131
6131
6131
5760
6131
6131
6395
6131
6131
2817
6131
2118
8687
2471
6131
6131
6131
6131
7338...

result:

points 1.0 good job! L = 19996

Test #7:

score: 21
Accepted
time: 10ms
memory: 4808kb

input:

2 9999
731433813
672900155
-154266178
-142062752
810401507
609673796
544462551
633906986
571738102
936132990
790930862
713932885
583772218
618694605
415964624
125339983
752948390
446516496
494161410
870044586
267348103
415149513
140247028
139903914
573253228
-211705903
596809434
509194500
671221940
...

output:

19998
000101110001100111000010001111001011100100011100110011000101110011001010011001001001011100110000101110010011100100111001010100110010001110001101101100110010011110010011000111001001100100011101001010111100111110010100100100111000110100010111101111100011000010001110010111110010100100011111000110...

input:

2 9999
19998
00010111000110011100001000111100101110010001110011001100010111001100101001100100100101110011000010111001001110010011100101010011001000111000110110110011001001111001001100011100100110010001110100101011110011111001010010010011100011010001011110111110001100001000111001011111001010010001111...

output:

4198
2380
6998
4198
4198
4198
6998
4198
4198
8541
4198
4198
4198
4198
4198
5400
4198
8286
3848
8849
4198
2037
5400
7980
2037
4198
4198
4198
4198
4198
4198
4198
7619
9045
4198
5400
4198
4198
4198
4198
2037
4198
4198
6998
4198
4198
4198
4198
4198
4198
8849
8849
7619
4198
4198
4198
4198
4198
4198
4198
...

result:

points 1.0 good job! L = 19998

Test #8:

score: 21
Accepted
time: 86ms
memory: 4880kb

input:

2 9997
999646439
999877567
999615045
999572458
999465340
998602736
998754430
998562475
998183998
998108258
997864409
997668387
997816125
997387979
997110884
996840136
996816135
996727915
996673898
996724983
996388637
996660759
996075504
996307507
996029274
994026101
995863929
995531258
994972765
994...

output:

19994
010000010000001000000010010010001000000000001001001001000100001000000010000100010010001001000010000010000100100100001001000010010001000100100010001001000010010010001000010010010010010010001000100100001001000010010010000010000100100100001000010010001001001001001001001001000010001000010010010000...

input:

2 9997
19994
01000001000000100000001001001000100000000000100100100100010000100000001000010001001000100100001000001000010010010000100100001001000100010010001000100100001001001000100001001001001001001000100010010000100100001001001000001000010010010000100001001000100100100100100100100100001000100001001...

output:

1088
1215
5472
1158
7944
1502
3135
3011
3625
7853
396
2376
2480
2718
3625
2224
66
645
2239
4329
2871
2002
349
4713
963
1081
1075
302
384
3422
345
3651
2980
2891
1884
3288
1711
128
1812
8221
4866
980
1683
3879
1471
4534
1183
5748
5420
4153
311
4251
9426
2070
1185
2363
212
4405
3576
6882
6758
1175
312...

result:

points 1.0 good job! L = 19994

Test #9:

score: 21
Accepted
time: 22ms
memory: 4888kb

input:

2 9997
998075413
999768563
996994821
995848879
992447573
993627169
993755793
993838328
990880244
992269976
991969312
992511252
990615969
990854518
989858767
989576734
990174788
990535036
988582131
988861974
988343926
988904854
988679289
987728654
988224499
988144927
987476186
986075661
984274493
983...

output:

19994
010000101010010011001000110100100110001000000111001010011000110010011000110100010110001100010101000100110010001010011001010001100000101100101010000010110000011000100110010001001100010100011001100100110001011000101001010100101010010001001000101010100100101010010100010100011010001011001010100010...

input:

2 9997
19994
01000010101001001100100011010010011000100000011100101001100011001001100011010001011000110001010100010011001000101001100101000110000010110010101000001011000001100010011001000100110001010001100110010011000101100010100101010010101001000100100010101010010010101001010001010001101000101100101...

output:

2180
455
485
911
9955
7271
6982
9890
737
2764
9364
1214
639
1960
414
8137
7579
7130
308
8277
1409
8801
9229
1705
333
9851
2686
7725
7995
9118
3287
9917
7353
1790
26
8313
6210
7875
2347
7552
3061
2690
30
9917
3008
9054
9725
9755
6626
9214
7276
3464
9615
8305
8076
2328
599
3845
1453
9722
9074
6986
675...

result:

points 1.0 good job! L = 19994

Test #10:

score: 21
Accepted
time: 10ms
memory: 4808kb

input:

2 9996
858247159
442798730
530600104
557785258
-353636825
-522042815
-470118868
-915939541
-785438325
-68695070
108509921
10169473
-237573210
730447976
-260998254
-253035962
158696722
-91003900
600314055
292558809
168182086
279048883
463103031
504100858
320637761
399185676
413728072
629957268
280982...

output:

19992
001010001001011101000111100101001100010110100101011100101100011011110010000110011001011000110101010111110010100100111100010101001100101110010001100100111100001110010111110010001010011110000111001010101010001110011101100010001101100111100100110100001110011100010100100101011110001011010100101011...

input:

2 9996
19992
00101000100101110100011110010100110001011010010101110010110001101111001000011001100101100011010101011111001010010011110001010100110010111001000110010011110000111001011111001000101001111000011100101010101000111001110110001000110110011110010011010000111001110001010010010101111000101101010...

output:

4729
7373
2242
2242
338
940
4729
4729
8569
940
7373
7373
9560
7373
482
940
2242
7373
940
4729
3470
7373
7373
7373
6705
7373
7373
1199
4729
4783
2242
7373
7373
4729
940
940
6705
2242
4729
940
7373
7373
940
7373
7373
7373
7373
940
6705
2242
4729
2242
6705
7373
2242
4729
6705
7373
7373
940
2242
2242
73...

result:

points 1.0 good job! L = 19992

Subtask #3:

score: 0
Program floppy Time Limit Exceeded

Test #11:

score: 72
Accepted
time: 28ms
memory: 9244kb

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:

11215
3597
17919
17919
16794
7409
7409
17919
17919
17919
17919
17919
37333
16794
38000
37333
17919
8605
16794
17919
27076
17919
17919
17919
17240
12582
27076
17919
17919
37333
17919
11215
17919
17919
17919
17919
17919
17919
7409
17919
17919
17919
584
32471
3597
32471
28370
17919
3597
17919
39520
373...

result:

points 1.0 good job! L = 79990

Test #12:

score: 72
Accepted
time: 32ms
memory: 9220kb

input:

3 39999
867402172
685901466
686671636
711501842
903386066
833531940
941869841
155613808
75348538
621222078
361531803
494133420
183601186
469266981
615102900
778500747
967242098
906173922
878275917
950695497
896291806
891834174
648534298
781268592
646594891
772566083
814129180
955538985
702320755
372...

output:

79998
001010110011000110010010110110110001100001001011011110001100011100010011100011110110001100010110011111000101100100100110101011000110001101100110010111000110011111000011101001001100010010111101010010001111100011001001001111100100011001001010001110001100100110011001111111010001011001001010011101...

input:

3 39999
79998
0010101100110001100100101101101100011000010010110111100011000111000100111000111101100011000101100111110001011001001001101010110001100011011001100101110001100111110000111010010011000100101111010100100011111000110010010011111001000110010010100011100011001001100110011111110100010110010010...

output:

26342
9725
33006
26342
4221
26342
26342
26342
22096
25742
4221
26342
26342
19941
31716
26342
37017
31716
16513
2293
26342
26342
16513
26342
31716
26342
31716
22096
31716
16513
16513
16513
7246
26342
16513
26342
29199
34715
26342
16513
16513
14546
13032
27508
16513
26342
26342
16513
4221
37017
26342
...

result:

points 1.0 good job! L = 79998

Test #13:

score: 0
Program floppy Time Limit Exceeded

input:

3
39999 79998
999942157 999920759 999874133 999902533 999819991 999831518 999785254 999798240 999745461 999681177 999690072 999678043 999529806 999656013 999367471 999501765 999498631 999326775 999353567 999256847 999285607 999067567 999153844 998988618 999045678 999017050 998767814 999006932 998853...

output:

79998
000100100100010001001000100100100100010010000100100010000100100100100100010010000100001000100001000000100100100100010000100100000010000010000100010000100001000100010010000010000000000010010001000100100100010001001001001000100100100100010010010010000010000100100010010010010001001001001000100100...

input:


output:


result: