QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71834#362. SparklersHe_Ren50 608ms9548kbC++232.2kb2023-01-12 01:28:582023-01-12 01:35:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 01:35:21]
  • 评测
  • 测评结果:50
  • 用时:608ms
  • 内存:9548kb
  • [2023-01-12 01:28:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

struct Data {
    ll a, b;
    Data(void) {}
    Data(ll _a, ll _b): a(_a), b(_b) {}
    inline bool type(void) const {
        return a <= b;
    }
};

inline bool operator < (const Data &p, const Data &q) {
    if (p.type() != q.type())
        return p.type();

    if (p.type())
        return p.a < q.a;
    else
        return p.b > q.b;
}

inline Data operator + (const Data &p, const Data &q) {
    ll t = max(p.a, p.a - p.b + q.a);
    return Data(t, -p.a + p.b - q.a + q.b + t);
}

int n, d;
int a[MAXN];

int fa[MAXN];
inline void init(int _n) {
    for (int i = 1; i <= _n; ++i)
        fa[i] = i;
}
int find(int u) {
    return fa[u] == u ? u : fa[u] = find(fa[u]);
}
inline void connect(int u, int v) {
    fa[find(u)] = find(v);
}

pii ids[MAXN];
Data dat[MAXN];

inline bool chk(ll m) {
    if (m > 2e9)
        return 1;

    dat[d] = Data(0, m);

    for (int i = 1; i < d; ++i)
        dat[i] = Data(a[i + 1] - a[i], m);

    for (int i = d + 1; i <= n; ++i)
        dat[i] = Data(a[i] - a[i - 1], m);

    set< pair<Data, int>> t;

    for (int i = 1; i <= n; ++i)
        if (i != d)
            t.emplace(dat[i], i);

    init(n);

    while (t.size()) {
        int x = t.begin() -> second;
        t.erase(t.begin());
        int y = x < d ? find(x + 1) : find(x - 1);

        if (y != d)
            t.erase(make_pair(dat[y], y));

        dat[y] = dat[y] + dat[x];
        fa[x] = y;

        if (y != d)
            t.emplace(dat[y], y);
        else if (dat[d].a > 0)
            return 0;
    }

    return 1;
}

int main(void) {
    int m;
    scanf("%d%d%d", &n, &d, &m);

    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);

    if (a[1] == a[n])
        return printf("0"), 0;

    int l = 1, r = 1e9;

    while (l < r) {
        int mid = (l + r) >> 1;

        if (chk((ll)m * mid * 2))
            r = mid;
        else
            l = mid + 1;
    }

    printf("%d", l);
    return 0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 3ms
memory: 3728kb

input:

10 9 2
0
1117660
2284171
3390084
3568342
4222750
5180454
6186411
6360445
6519656

output:

181102

result:

ok single line: '181102'

Test #2:

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

input:

3 2 1
0
368765
1493921

output:

373481

result:

ok single line: '373481'

Test #3:

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

input:

9 8 4
0
1970871
2488111
3723411
5581758
7596649
8984403
9989980
10451978

output:

168215

result:

ok single line: '168215'

Test #4:

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

input:

20 18 1
0
462590
635597
1653028
1731039
2632280
2993419
3958675
4824859
4923991
5874922
6721441
7856685
8109245
8187843
8916119
9662776
10617094
11598860
11759660

output:

477159

result:

ok single line: '477159'

Test #5:

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

input:

20 19 1
0
16714
600564
1738550
2860146
3233681
3470376
3511936
4127893
5089595
5771375
5923055
6712524
7645593
7839588
7939256
8270988
8365309
8565641
8764207

output:

242986

result:

ok single line: '242986'

Test #6:

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

input:

20 19 1
0
360130
416278
565928
1137578
1907790
2582414
3700996
4219574
4315031
4708493
5703532
6750886
7008779
7292334
7354499
8425871
8951795
9692673
9903623

output:

318641

result:

ok single line: '318641'

Test #7:

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

input:

20 3 1
0
497352
601758
1175884
1245741
1585758
1746236
2367513
2732420
2739779
3351827
3525038
4143423
4321819
5000239
5107430
5312137
5958753
6370846
6513352

output:

173188

result:

ok single line: '173188'

Test #8:

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

input:

20 7 1
0
416112
1276119
1776741
1971354
3051516
3964787
4752968
5114629
5456785
5783476
6450733
7492246
8117636
8726706
9380206
9424138
9680412
10381694
11143315

output:

394091

result:

ok single line: '394091'

Test #9:

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

input:

20 17 1
0
418275
1609767
2826602
4126911
5045015
5863900
5903447
6048863
6976925
7826789
8397913
8479522
9312544
9618482
9751692
10846799
12065875
12985857
14274374

output:

547554

result:

ok single line: '547554'

Test #10:

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

input:

20 5 1
0
636862
675532
1067405
2149723
2433765
3448119
4927611
5075453
6024114
6742671
7335495
8053680
9461089
10479891
11154362
11537902
11790723
12326305
13349359

output:

374282

result:

ok single line: '374282'

Test #11:

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

input:

20 9 1
0
253324
316843
568058
673961
952771
1319011
1398887
1748830
1895752
2246598
2269716
2344119
2451418
2690003
2985338
3065614
3143399
3495892
3568533

output:

124217

result:

ok single line: '124217'

Test #12:

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

input:

20 11 1
0
51952
61227
162819
249127
306399
334761
382780
449122
509397
542856
610609
616723
637063
646745
686393
770737
862074
908186
946759

output:

25317

result:

ok single line: '25317'

Test #13:

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

input:

20 20 1
0
560429
1501879
2074034
3034586
3927746
4203223
4704487
5719669
6398636
6727143
7650938
8442426
9196467
9374450
9518016
10137750
10914536
11539863
12123154

output:

330901

result:

ok single line: '330901'

Test #14:

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

input:

20 18 1
0
238996
608018
1366723
1785069
2539784
3289307
3602420
4757227
5445099
5644989
6150519
7171436
7964903
9199069
9472670
10160202
11298237
11504431
12150241

output:

374983

result:

ok single line: '374983'

Test #15:

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

input:

20 16 1
0
260310
303643
510297
1043552
1456874
1889988
2034528
2320694
2791007
3106279
3221006
3686585
4034261
4101785
4113243
4346119
4405697
4733785
5087878

output:

139122

result:

ok single line: '139122'

Test #16:

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

input:

20 8 1
0
484204
551742
1091736
1375852
1491742
1695121
2025199
2649991
2689456
3395295
4015308
4099000
4429963
4591520
5011483
5300133
5567208
6302488
6642143

output:

176556

result:

ok single line: '176556'

Test #17:

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

input:

20 6 1
0
62927
133948
189568
367293
532858
671097
693145
766893
880530
939114
944530
1061492
1137014
1312489
1390117
1549261
1657553
1800303
1929758

output:

69120

result:

ok single line: '69120'

Test #18:

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

input:

20 14 1
0
223799
635453
1081261
1241909
1496302
1622006
1780758
1882704
2140804
2503655
2564678
2565246
3012521
3485082
3933129
3986311
4363178
4395662
4701534

output:

223638

result:

ok single line: '223638'

Test #19:

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

input:

20 5 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

output:

0

result:

ok single line: '0'

Test #20:

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

input:

2 1 1
0
1000000000

output:

500000000

result:

ok single line: '500000000'

Test #21:

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

input:

1 1 1
0

output:

0

result:

ok single line: '0'

Subtask #2:

score: 30
Accepted

Dependency #1:

100%
Accepted

Test #22:

score: 30
Accepted
time: 7ms
memory: 3660kb

input:

732 262 7
0
629941
1835167
3075849
3632747
5477365
7690179
11300419
14778007
18359892
20279775
21163002
22029502
23636159
23778620
24102872
27453702
30784655
35027716
36072504
36591660
41988236
46473109
48716186
49542064
50631925
51952471
57334048
61174375
62942938
67795840
70872460
71304388
7568304...

output:

211260

result:

ok single line: '211260'

Test #23:

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

input:

568 176 10
0
4822188
12835213
21145111
24069578
25428693
37689591
44528013
53494376
62691761
74853861
87803170
99563518
103793768
116721590
124706385
130511788
140228697
151031085
156719085
163061026
163972683
168129081
176494838
179979518
193257722
204266763
207017659
212179406
223965988
232681126
...

output:

88184

result:

ok single line: '88184'

Test #24:

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

input:

729 47 4
0
533644
614452
918872
1066928
1633243
2052575
2487683
2677252
2956221
3502185
4032500
4606055
4794447
5434290
5685999
5741100
6004356
6550878
6840957
7439030
7730019
8034922
8440581
8528403
9017686
9170499
9576985
9721356
10115002
10425275
10673108
11300867
11667482
12163892
12313691
12846...

output:

59242

result:

ok single line: '59242'

Test #25:

score: 0
Accepted
time: 8ms
memory: 3864kb

input:

1000 16 1
0
300418
720839
1101334
1270642
1358485
1699613
2031751
2076100
2078250
2167047
2223905
2537060
2672439
2879343
3014590
3445224
3884089
4118024
4432980
4484003
4777108
5200064
5540984
5890142
6227183
6625240
6942951
7338632
7348721
7383868
7709001
7793033
7912649
8267321
8447335
8873296
89...

output:

124746

result:

ok single line: '124746'

Test #26:

score: 0
Accepted
time: 9ms
memory: 3728kb

input:

1000 134 1
0
157000
165508
193836
347260
355223
653813
723441
766606
877569
1153254
1380323
1690537
1975409
2111433
2376749
2665106
2914807
3080873
3485222
3755909
3805411
4001843
4137840
4494580
4805592
5039944
5276573
5561247
5690839
6040123
6111803
6184345
6565504
6885171
6988886
7160962
7455902
...

output:

102156

result:

ok single line: '102156'

Test #27:

score: 0
Accepted
time: 8ms
memory: 5776kb

input:

1000 167 1
0
337310
734264
1228171
1775353
1937515
1966717
2134352
2626557
3090581
3311943
3632694
3760763
4140320
4492696
5133898
5367854
5677466
5879158
6422820
6961196
7515753
8203291
8286108
8479558
8486789
8700986
9096429
9530532
9724870
10239491
10937150
11172992
11835729
12509154
13162049
137...

output:

184550

result:

ok single line: '184550'

Test #28:

score: 0
Accepted
time: 12ms
memory: 3768kb

input:

1000 583 1
0
1155216
2243968
3441256
5297971
6209914
7762324
9015919
9734409
10298287
12090390
13680839
15187680
16616775
17433179
18990924
19345637
20328209
21047781
22310574
23253675
24084243
25052744
26433441
26505138
26771451
27773965
28197193
29214668
29604538
31446792
31634297
33050511
3342317...

output:

507288

result:

ok single line: '507288'

Test #29:

score: 0
Accepted
time: 10ms
memory: 5808kb

input:

1000 648 1
0
149277
558491
833172
1061298
1159483
1289104
1512423
1829467
1932459
2206872
2427755
2682759
2982638
3167870
3203058
3379660
3581887
3642593
4001751
4241647
4652799
4829201
5197712
5208113
5569955
5587313
5858867
6044105
6335886
6640171
6724803
6804688
7017976
7450352
7879658
8063683
84...

output:

135848

result:

ok single line: '135848'

Test #30:

score: 0
Accepted
time: 12ms
memory: 3796kb

input:

1000 795 1
0
686899
726596
1248874
1493856
3062405
3640995
4212376
5570483
6826974
7121530
7833336
7901177
9464878
10585555
11892848
12528701
13269468
14456032
15998686
16803364
17796407
17884537
18272340
18495999
19828084
21233255
22510945
23456317
23827759
25261874
25370977
25481392
26520168
27639...

output:

470218

result:

ok single line: '470218'

Test #31:

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

input:

1000 759 1
0
292968
1286267
2746799
3008098
3957531
4083400
4553850
4986193
5454234
6032115
7233640
8832257
9344907
10846015
12427055
13269890
13699022
14707280
16218583
17252404
17774007
18676352
19819174
19838334
20655789
21327375
21561066
21565972
22261363
23332536
23645399
25210904
26335730
2763...

output:

554416

result:

ok single line: '554416'

Test #32:

score: 0
Accepted
time: 13ms
memory: 3832kb

input:

1000 458 1
0
504827
848739
1086846
1573082
1728990
1823619
2014935
2220271
2557191
3044420
3330136
3678193
4215244
4491655
4635399
4825647
5307762
5723073
6193581
6343163
6412549
6939317
7448527
7653234
8109406
8247186
8694349
9107982
9256817
9308402
9897870
10061482
10680266
11210653
11660005
11804...

output:

157794

result:

ok single line: '157794'

Test #33:

score: 0
Accepted
time: 9ms
memory: 3804kb

input:

1000 456 1
0
443096
828592
853300
2166760
3763688
4474083
5605059
5924755
6028046
7560910
9185540
9439212
10435851
11748693
12592624
13982847
15349361
15813754
16470798
16918094
17846923
18854493
19038890
20646465
21723048
22912066
23442080
24187299
24764257
25671485
27317603
28811914
29024954
30682...

output:

427924

result:

ok single line: '427924'

Test #34:

score: 0
Accepted
time: 8ms
memory: 3704kb

input:

1000 853 1
0
582236
707105
1485183
1565456
2305904
2945856
3588155
3639466
3983620
4616508
5234636
5253012
5318842
5973684
6450836
7271793
7564151
7828478
8062226
8365405
9058247
9229188
9935587
10236602
10498734
10859622
11459300
11790218
11802398
12225935
12315792
12739191
13278401
13767688
138153...

output:

216536

result:

ok single line: '216536'

Test #35:

score: 0
Accepted
time: 8ms
memory: 3832kb

input:

1000 678 1
0
1423965
1720061
2770130
3164514
4617891
4997811
5376811
6259000
6374700
7470084
8144917
8322317
9000489
10446643
11863354
13237339
14715403
16069900
16610423
17007435
17434598
17563153
18434143
19847695
20451294
20754484
20996075
21921238
22485230
22769421
22889959
23834563
25066889
251...

output:

391962

result:

ok single line: '391962'

Test #36:

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

input:

1000 79 1
0
146771
587793
895168
1125168
1335036
1452933
1526650
1918223
2012769
2582329
3104377
3194601
3300365
3442735
3461648
3982416
4296813
4857404
4920820
5369944
5920776
6374534
6792185
6999303
7246112
7728670
8213772
8686243
8874923
8977574
9463313
9471641
9583689
9890568
10222513
10395290
1...

output:

253173

result:

ok single line: '253173'

Test #37:

score: 0
Accepted
time: 13ms
memory: 3712kb

input:

1000 80 1
0
8138
16097
55052
132991
173831
191917
291217
349204
387976
510410
538297
566672
684616
763244
787637
872089
996937
1099484
1222638
1282821
1406083
1530218
1560976
1622871
1740617
1831309
1868920
1940406
2016359
2041718
2176541
2311739
2434375
2484665
2541798
2626695
2666664
2684068
26903...

output:

40462

result:

ok single line: '40462'

Test #38:

score: 0
Accepted
time: 12ms
memory: 5832kb

input:

1000 696 1
0
287744
552034
1939818
2810607
3742043
4697514
6394294
6952380
7749944
8885258
9610948
10729116
11520305
11842566
13495115
14422538
15759779
16950184
17730382
18723101
19644608
20937824
22314327
23483431
24832581
25116142
26646011
27722092
29174150
29817352
31121574
32062527
33269915
335...

output:

509406

result:

ok single line: '509406'

Test #39:

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

input:

1000 946 1
0
321611
583133
948259
1393880
1500586
1817398
2169635
2570310
3022668
3464202
3619114
4306711
5208482
5807290
6072910
6553270
7162827
7731663
8862192
9108146
10221512
11221274
12152335
12304641
12874083
13391968
13881281
14409814
14949312
14998383
16001073
16039140
16428078
17264220
1761...

output:

337421

result:

ok single line: '337421'

Test #40:

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

input:

1000 356 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

output:

0

result:

ok single line: '0'

Subtask #3:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #41:

score: 50
Accepted
time: 608ms
memory: 9548kb

input:

64944 48942 10
0
132465
271583
422988
502187
616524
781356
971483
1147338
1201136
1209297
1270299
1457035
1547500
1588836
1737679
1861812
1861942
1901796
2089337
2273423
2299172
2409479
2564115
2578298
2635887
2711417
2787082
2855980
2873745
2890630
3061756
3123156
3138851
3214185
3271978
3387891
35...

output:

770

result:

ok single line: '770'

Test #42:

score: 0
Accepted
time: 32ms
memory: 3868kb

input:

2544 281 1
0
13570
15088
28249
36255
45228
62179
72750
86758
103113
114107
131223
141045
143547
154723
164061
164235
170037
172113
188776
199968
207329
209111
213786
224815
227824
242863
252776
258322
264369
268191
275815
276927
288910
291212
305052
307999
308599
311270
319887
330210
338481
344210
3...

output:

5144

result:

ok single line: '5144'

Test #43:

score: 0
Accepted
time: 168ms
memory: 7156kb

input:

18415 12647 10
0
160166
309369
442188
538258
547315
732840
893693
1054182
1227007
1319585
1448113
1469386
1478740
1606374
1748696
1865136
1917827
1996876
2120441
2299781
2455034
2467452
2615635
2656844
2818626
2836288
2870353
2915415
2964175
3040687
3222809
3331537
3390063
3543142
3674063
3702136
37...

output:

2716

result:

ok single line: '2716'

Test #44:

score: -50
Time Limit Exceeded

input:

100000 9658 1
0
3399
13257
14737
22743
34296
48139
56795
56994
62660
65829
67953
79213
92194
106575
109473
121648
122496
134931
138418
147891
152601
159683
165707
177526
187356
198293
201781
202208
207495
220441
225027
238653
245350
246364
253877
258948
270098
280392
287306
287578
299075
301003
3136...

output:


result: