QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414966#2929. Concert RehearsalTheSleepyDevilAC ✓45ms35080kbC++206.4kb2024-05-20 05:59:082024-05-20 05:59:09

Judging History

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

  • [2024-05-20 05:59:09]
  • 评测
  • 测评结果:AC
  • 用时:45ms
  • 内存:35080kb
  • [2024-05-20 05:59:08]
  • 提交

answer

 /*
     Hell, 'til I reach Hell, I ain't scared
     Mama checkin' in my bedroom, I ain't there
                                                */
    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;

    #define Major  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define TxtIO   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    #define read(a,n) for(int i = 0 ; i<n ; i++) cin>>a[i];
    #define write(a) for(auto x : a) cout<<x<<" ";
    #define int long long
    #define pb push_back
    #define all(a)  a.begin(),a.end()
    #define el "\n"

    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    const int inf=4e18;

    int dx[]={1,0,-1,0,1,1,-1,-1};
    int dy[]={0,1,0,-1,1,-1,1,-1};

    const int mod=1e9+7;
    const int MAX =1e6+7;

   // ---------------------------Function----------------------------------//
    int n,p,k;
     vector<array<int,2>>arr;
     vector<int>pre;
    int check(int i, int x) {
    int cnt = pre[n - 1] * (x / n);
    if(i + x % n >= n)
        cnt += pre[n - 1] - pre[i - 1] + pre[(i + x % n) % n];
    else {
        cnt += pre[i + x % n];
        if(i)
            cnt -= pre[i - 1];
    }
    return cnt;
}
     int vis[MAX],ans[MAX],base[MAX];
    void TestCake(){
        cin>>n>>p>>k;

        int sum=0;
        for(int i=0;i<n;i++){
            int x;cin>>x;
            arr.pb({x,i});sum+=x;
            pre.pb(sum);
        }
        vector<array<int,2>>nxt;
        for(int i=0;i<n;i++){
            int l=0,r=1e9,z=1;
            while(l<=r){
                int mid=(l+r)/2;
                if(check(i,mid)>p){
                    z=mid;
                    r=mid-1;
                }
                else{
                    l=mid+1;
                }

            }
//        cout<<check(i,r)<<" "<<i<<" "<<r<<el;

           nxt.pb({(i+z)%n,z});
//           cout<<i<<" "<<(i+r)%n<<" "<<r<<el;
        }
        memset(vis,-1,sizeof vis);
        int st=0,cnt=0;
        vector<array<int,3>>here;
        while(vis[st]==-1){
            vis[st]=cnt;
            here.pb({st,nxt[st][0],nxt[st][1]});
            st=nxt[st][0];
            cnt++;
        }
         here.pb({st,nxt[st][0],nxt[st][1]});
//        cout<<cnt<<el;
//          for(auto x : here){
//             cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<el;
//           }
        if(cnt>k){
            for(int i=0;i<here.size()-1&&k--;i++){
                 int l=here[i][0],r=here[i][1];
//                 cout<<l<<" "<<r<<el;
                 int m3aya=here[i][2]/n,zyada=here[i][2]%n;
                 ans[0]+=m3aya;
                 ans[n]-=m3aya;
                 if(!zyada)continue;
                 r=(l+zyada-1);
                 r+=n;r%=n;

                 ans[l]++;
                 if(r>=l){
                    ans[r+1]--;
                 }
                 else{
                    ans[n]--;
                    ans[0]++;
                    ans[r+1]--;
                 }
            }

        }
        else{
            k-=cnt;

//            cout<<k<<" "<<cnt<<el;
            int id=0;
            for(int i=0;i<here.size();i++){
                if(here[i]==here.back()){id=i;break;}
            }
            for(int i=id;i<here.size()-1;i++){
                 int l=here[i][0],r=here[i][1];
//                 cout<<l<<" "<<r<<el;
                 int m3aya=(here[i][2]/n),zyada=(here[i][2]%n);

                 ans[0]+=m3aya;
                 ans[n]-=m3aya;
                 if(!zyada)continue;
                 r=(l+zyada-1);
                 r+=n;r%=n;
//                 cout<<m3aya<<" "<<zyada<<" "<<l<<" "<<r<<el;
                 ans[l]++;
                 if(r>=l){
                    ans[r+1]--;
                 }
                 else{
                    ans[n]--;
                    ans[0]++;
                    ans[r+1]--;
                 }
                 //

            }
            for(int z=1;z<n;z++)ans[z]+=ans[z-1];
            int sz=(cnt-id);
            int have=(k/sz),bzboz=(k%sz);
            for(int i=0;i<n;i++){
//                cout<<ans[i]<<" "<<have<<el;
                ans[i]+=(ans[i]*(have));

            }

            //base
            for(int i=0;i<id;i++){
                 int l=here[i][0],r=here[i][1];
//                 cout<<l<<" "<<r<<el;
                 int m3aya=here[i][2]/n,zyada=here[i][2]%n;
                 base[0]+=m3aya;
                 base[n]-=m3aya;
                  if(!zyada)continue;
                  r=(l+zyada-1);
                 r+=n;r%=n;

                 base[l]++;
                 if(r>=l){
                    base[r+1]--;
                 }
                 else{
                    base[n]--;
                    base[0]++;
                    base[r+1]--;
                 }
            }
            //
           for(int i=id;i<here.size()-1&&bzboz--;i++){
                 int l=here[i][0],r=here[i][1];
//                 cout<<l<<" "<<r<<el;
                 int m3aya=here[i][2]/n,zyada=here[i][2]%n;
                 base[0]+=m3aya;
                 base[n]-=m3aya;
                  if(!zyada)continue;
                  r=(l+zyada-1);
                 r+=n;r%=n;

                 base[l]++;
                 if(r>=l){
                    base[r+1]--;
                 }
                 else{
                    base[n]--;
                    base[0]++;
                    base[r+1]--;
                 }
            }
            int mn=inf;
            for(int i=1;i<n;i++)base[i]+=base[i-1];
            for(int i=0;i<n;i++){
                ans[i]+=base[i];
               mn=min(mn,ans[i]);
            }
            cout<<mn<<el;return;
        }

            int mn=ans[0];
//          cout<<ans[0]<<" ";
            for(int z=1;z<n;z++){
                ans[z]+=ans[z-1];
//                cout<<ans[z]<<" ";
                mn=min(mn,ans[z]);
            }
            cout<<mn<<el;
    }
    //------------------------------Main---------------------------//
    signed main(){
        Major
        int T = 1;
//        cin >> T;
        while(T--){
            TestCake();
        //       cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
        }
        return 0;
    }

详细

Test #1:

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

input:

3 20 10
6
9
5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

5 11 2
5
5
5
5
5

output:

0

result:

ok single line: '0'

Test #3:

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

input:

7 11 3
1
2
3
4
5
6
7

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4 8 9
2
7
2
3

output:

4

result:

ok single line: '4'

Test #5:

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

input:

1 3 7
2

output:

7

result:

ok single line: '7'

Test #6:

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

input:

1 1000000000 1000000000
1

output:

1000000000000000000

result:

ok single line: '1000000000000000000'

Test #7:

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

input:

5 999999999 999999999
2
1
4
7
3

output:

58823528941176471

result:

ok single line: '58823528941176471'

Test #8:

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

input:

5 5 1000
2
2
2
2
2

output:

400

result:

ok single line: '400'

Test #9:

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

input:

980 991 978
2
1
2
1
2
3
1
1
1
3
3
3
2
2
2
2
3
3
1
3
1
2
2
3
1
2
3
3
2
3
1
2
2
3
1
3
1
3
2
2
2
1
1
2
3
3
1
2
1
1
1
2
2
2
3
3
2
1
3
3
1
3
3
1
1
2
1
1
1
1
2
1
2
3
2
1
1
3
3
2
2
1
3
3
3
2
2
3
1
2
3
3
2
2
3
2
3
2
2
2
1
3
3
1
1
3
1
2
2
2
2
1
2
2
1
1
3
2
1
1
3
1
2
3
3
3
3
3
2
2
2
3
3
1
1
2
1
3
3
3
2
2
2
3
...

output:

492

result:

ok single line: '492'

Test #10:

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

input:

980 967 994
6
1
4
6
10
10
8
5
5
9
2
8
10
1
8
7
10
1
7
3
7
1
4
10
2
5
7
5
2
5
4
9
4
9
8
1
9
8
9
8
4
1
3
2
4
9
4
2
8
7
5
7
9
9
1
4
10
10
3
7
5
4
1
1
6
7
8
6
6
9
9
9
10
10
9
10
9
10
7
9
4
3
9
8
3
5
2
1
3
5
9
3
6
4
10
8
2
2
8
4
2
4
8
1
2
9
1
2
6
10
3
4
9
9
9
10
10
10
2
6
2
5
5
7
10
9
9
3
10
8
4
9
6
3
10...

output:

179

result:

ok single line: '179'

Test #11:

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

input:

995 997 962
48
41
40
40
41
50
45
43
42
49
40
49
43
50
50
47
47
48
41
43
40
43
41
43
41
49
43
46
41
48
45
42
44
47
44
46
44
46
40
42
43
45
43
45
40
41
49
41
45
40
48
43
50
48
45
43
50
46
44
48
50
48
44
44
42
41
48
50
49
41
48
48
48
46
45
43
47
48
49
48
41
40
46
44
43
40
42
44
43
46
43
43
47
42
43
40
...

output:

21

result:

ok single line: '21'

Test #12:

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

input:

962 981 996
85
234
239
585
600
759
968
366
415
610
749
684
701
524
796
720
733
404
182
216
856
378
210
643
306
203
831
212
413
171
568
562
406
793
475
937
64
958
209
81
563
566
810
531
903
600
820
914
395
502
216
673
573
882
604
161
720
461
43
105
822
406
476
446
60
285
268
795
637
561
129
962
619
3...

output:

1

result:

ok single line: '1'

Test #13:

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

input:

992 965 983
567
702
416
603
427
787
855
407
646
406
964
869
518
484
721
455
539
433
440
695
376
932
704
794
928
946
642
607
897
592
336
904
852
458
377
618
645
800
512
924
840
745
819
791
539
520
750
896
452
441
573
678
377
927
789
425
458
318
628
564
738
580
347
861
913
407
833
721
421
849
941
415
...

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 34ms
memory: 30036kb

input:

191517 972629409 971799494
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

4935336119068

result:

ok single line: '4935336119068'

Test #15:

score: 0
Accepted
time: 44ms
memory: 34228kb

input:

200000 999999999 1000000000
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

2499999995000

result:

ok single line: '2499999995000'

Test #16:

score: 0
Accepted
time: 39ms
memory: 31696kb

input:

197730 987961966 960644645
1
2
3
2
2
3
3
3
1
1
2
2
2
1
1
1
1
1
2
2
1
3
3
3
2
1
3
1
1
3
2
2
2
3
2
3
2
2
3
3
1
1
3
1
3
1
3
3
2
2
3
3
1
2
2
3
1
3
3
1
1
1
2
3
2
1
1
1
1
3
2
3
3
3
3
2
1
2
1
2
2
3
3
3
1
3
2
1
3
3
1
1
1
1
2
2
3
3
2
2
3
3
1
2
2
1
1
1
1
2
2
1
2
3
1
2
1
3
2
1
1
1
2
3
2
2
1
3
2
2
3
3
1
1
3
3
2...

output:

2400352995224

result:

ok single line: '2400352995224'

Test #17:

score: 0
Accepted
time: 33ms
memory: 29684kb

input:

192667 981519468 981087383
3
4
10
7
8
1
5
1
7
8
8
4
7
1
5
1
6
1
2
1
6
9
3
9
5
10
7
10
3
6
2
6
8
9
5
2
10
4
10
1
7
1
9
5
3
6
9
6
10
7
9
5
1
6
1
6
5
7
10
10
6
10
8
4
6
3
1
9
1
6
6
9
4
7
5
6
5
7
1
3
6
6
3
4
1
9
4
9
8
8
2
2
1
3
2
7
5
3
7
6
2
10
5
6
5
9
1
8
9
9
9
5
3
2
9
4
3
10
9
9
3
7
10
7
3
3
10
7
2
3
...

output:

909686916772

result:

ok single line: '909686916772'

Test #18:

score: 0
Accepted
time: 33ms
memory: 31156kb

input:

198400 996823531 976959788
43
47
44
50
44
46
41
40
50
47
43
49
48
42
47
45
47
41
43
41
40
46
49
44
46
48
46
46
42
42
45
47
50
46
48
50
50
40
45
43
40
43
45
44
47
49
50
44
42
45
42
49
48
43
43
45
50
47
42
44
49
49
42
49
48
45
44
40
50
40
42
42
42
46
47
47
49
42
42
43
40
41
47
41
49
41
46
50
44
42
43
...

output:

109090881841

result:

ok single line: '109090881841'

Test #19:

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

input:

195647 974282103 972882622
432
354
760
958
58
181
803
419
310
137
506
88
972
726
834
479
408
215
752
474
552
689
167
503
691
726
563
418
622
186
661
123
321
214
882
152
137
14
791
470
712
299
425
403
85
221
749
649
376
342
422
89
229
317
349
508
780
635
626
731
232
741
644
318
364
864
729
921
370
80...

output:

9685174728

result:

ok single line: '9685174728'

Test #20:

score: 0
Accepted
time: 34ms
memory: 30968kb

input:

193934 958782661 952100506
173885
135659
161389
190344
153931
178916
120485
140968
147416
103017
185975
114364
145315
119943
194090
119852
103788
117034
198084
123982
176866
171769
102811
157954
118763
153238
148182
149743
106357
135115
171583
153426
114860
100981
195778
119457
111558
184289
182621
...

output:

31368417

result:

ok single line: '31368417'

Test #21:

score: 0
Accepted
time: 40ms
memory: 35080kb

input:

197587 969369471 958326403
562864350
179110069
840760703
539101570
619018241
591243727
802298459
341842285
319778295
829272269
704464734
948191740
521694671
947718773
668891006
156315045
933274269
514307940
724872162
282336223
4812411
925022043
488956634
164962689
713042567
156733510
795980505
30329...

output:

7268

result:

ok single line: '7268'

Test #22:

score: 0
Accepted
time: 34ms
memory: 34492kb

input:

190729 998654926 953563254
806691863
488651193
814044068
712278157
771718816
739778712
544717778
895515396
732845471
878834165
414327410
371586223
890270288
885258319
842740469
723233201
679517241
751573053
857863507
706771221
716899272
363503588
456315561
860921465
801645319
635247679
624753451
846...

output:

5667

result:

ok single line: '5667'

Test #23:

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

input:

3 9 5
1
2
3

output:

7

result:

ok single line: '7'

Test #24:

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

input:

4 10 5
3
2
4
6

output:

2

result:

ok single line: '2'

Test #25:

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

input:

3 10 2
5
6
7

output:

0

result:

ok single line: '0'