QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376231 | #4571. Even Split | InfinityNS# | AC ✓ | 89ms | 5708kb | C++14 | 2.3kb | 2024-04-04 00:11:43 | 2024-04-04 00:11:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
int l,n;
int a[N],x[N];
int L[N],R[N];
int maxSteps,steps;
bool Check(int mn,int mx,bool reconstruct=false){
x[0]=0;x[n]=l;
L[0]=R[0]=0;
a[n+1]=l;
for(int i=1;i<=n;i++){
L[i]=max(L[i-1]+mn,a[i]);
R[i]=min(R[i-1]+mx,a[i+1]);
if(L[i]>R[i])return false;
}
if(R[n]<l)return false;
if(reconstruct){
//for(int i=1;i<=n;i++){
// printf("L:%i R:%i\n",L[i],R[i]);
//}
for(int i=n-1;i>=1;i--){
x[i]=max(L[i],x[i+1]-mx);
}
}
return true;
}
int Get(int mn,bool reconstruct=false){
int top=l,bot=mn,ans=l;
while(top>=bot){
int mid=top+bot>>1;
if(Check(mn,mid)){
top=mid-1;
ans=mid;
}else{
bot=mid+1;
}
}
if(reconstruct){
Check(mn,ans,true);
}
return ans-mn;
}
int Find(){
int top=l/n,bot=1,ans=1;
while(top>=bot){
int mid=top+bot>>1;
if(Check(mid,l)){
bot=mid+1;
ans=mid;
}else{
top=mid-1;
}
}
return ans;
}
void Solve(){
int bot=1;
int ans=Find();
int top=ans-1;
while(top>=bot){
int mid=top+bot>>1;
int best1=Get(mid);
int best2=Get(mid+1);
if(best2<best1){
bot=mid+1;
}else{
top=mid-1;
ans=mid;
}
}
//printf("mn:%i diff:%i\n",ans,Get(ans));
Get(ans,true);
/*x[0]=0;x[n]=l;
for(int i=1;i<n;i++){
x[i]=a[i];
}
steps=0;
while(true){
steps++;
bool change=false;
for(int i=n-1;i>=1;i--){
int newX=max(a[i],min(a[i+1],(x[i-1]+x[i+1])/2));
if(newX!=x[i])change=true;
}
if(!change)break;
}
maxSteps=max(maxSteps,steps);*/
}
const int mxn=1e5;
const int mxl=1e9;
mt19937 rng(time(0));
void Gen(){
n=rng()%mxn+1;
l=rng()%(mxl-n-1)+n+1;
set<int> used;
auto Bad=[&](int x){
return x<=0 || x>=l || used.count(x);
};
for(int i=1;i<=n;i++){
a[i]=rng()%(l-1)+1;
int j=0;
while(Bad(a[i]+j) && Bad(a[i]-j)){
j++;
}
if(Bad(a[i]+j))a[i]-=j;
else a[i]+=j;
used.insert(a[i]);
}
sort(a+1,a+1+n);
}
const int tests=1e3;
void Test(){
for(int test=0;test<tests;test++){
Gen();
printf("generated test %i\n",test);
Solve();
printf("test %i: %i\n",test,steps);
}
printf("%i\n",maxSteps);
}
int main(){
//Test();
scanf("%i %i",&l,&n);
for(int i=1;i<=n;i++)scanf("%i",&a[i]);
Solve();
for(int i=1;i<=n;i++)printf("%i %i\n",x[i-1],x[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
input:
6 3 1 3 5
output:
0 2 2 4 4 6
result:
ok Minimal imbalance is 0
Test #2:
score: 0
Accepted
time: 0ms
memory: 4148kb
input:
10 2 1 2
output:
0 2 2 10
result:
ok Minimal imbalance is 6
Test #3:
score: 0
Accepted
time: 0ms
memory: 4144kb
input:
100 10 14 26 29 31 34 42 44 48 49 68
output:
0 14 14 26 26 29 29 32 32 35 35 42 42 45 45 48 48 68 68 100
result:
ok Minimal imbalance is 29
Test #4:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
100 10 3 42 45 58 69 73 75 78 84 88
output:
0 21 21 42 42 46 46 58 58 69 69 73 73 77 77 81 81 85 85 100
result:
ok Minimal imbalance is 17
Test #5:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
100 10 12 15 24 25 30 45 55 64 80 86
output:
0 12 12 18 18 24 24 30 30 36 36 45 45 58 58 72 72 86 86 100
result:
ok Minimal imbalance is 8
Test #6:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
100 10 10 46 50 57 59 65 76 79 80 90
output:
0 23 23 46 46 50 50 57 57 61 61 65 65 76 76 80 80 84 84 100
result:
ok Minimal imbalance is 19
Test #7:
score: 0
Accepted
time: 0ms
memory: 4112kb
input:
100 10 3 5 23 34 36 42 72 81 84 91
output:
0 5 5 10 10 23 23 34 34 42 42 57 57 72 72 81 81 86 86 100
result:
ok Minimal imbalance is 10
Test #8:
score: 0
Accepted
time: 50ms
memory: 5424kb
input:
1000000000 100000 234 521 2233 5010 10213 15298 22181 29569 37404 41370 46544 52606 58851 73956 74520 84776 102335 111406 140442 143688 161164 166404 166924 167716 185557 194472 213634 230507 241622 244806 303238 320282 328153 335228 339419 348046 353158 357866 369691 377344 386277 402535 409037 417...
output:
0 234 234 521 521 2233 2233 5010 5010 10213 10213 15298 15298 22181 22181 29569 29569 37404 37404 41370 41370 46544 46544 52606 52606 58851 58851 73956 73956 74520 74520 84776 84776 102335 102335 111406 111406 140442 140442 143688 143688 161164 161164 166404 166404 166924 166924 167716 167716 185557...
result:
ok Minimal imbalance is 58553
Test #9:
score: 0
Accepted
time: 43ms
memory: 5400kb
input:
1000000000 100000 9821 14877 29979 35144 54431 56557 59891 72599 75587 121025 122887 131740 134087 139909 173981 174231 204091 207393 215446 224891 231631 234220 250672 259032 262950 267369 273374 273704 277250 291380 313014 315589 320121 338235 340357 351633 353626 362050 374468 376865 414050 41502...
output:
0 9821 9821 14877 14877 29979 29979 35144 35144 54431 54431 56557 56557 59891 59891 72599 72599 75587 75587 121025 121025 122887 122887 131740 131740 134087 134087 139909 139909 173981 173981 174231 174231 204091 204091 207393 207393 215446 215446 224891 224891 231631 231631 234220 234220 250672 250...
result:
ok Minimal imbalance is 61981
Test #10:
score: 0
Accepted
time: 51ms
memory: 5660kb
input:
1000000000 100000 4042 5042 7422 12401 15821 25327 35801 49225 68723 70197 83123 121581 133929 155017 185876 197018 199980 207705 210442 216704 276702 277043 279595 305639 313551 344704 348884 360171 362803 370412 371572 372244 394028 418234 431550 435436 436500 436512 443397 445171 454725 459496 46...
output:
0 4042 4042 5042 5042 7422 7422 12401 12401 15821 15821 25327 25327 35801 35801 49225 49225 68723 68723 70197 70197 83123 83123 121581 121581 133929 133929 155017 155017 185876 185876 197018 197018 199980 199980 207705 207705 210442 210442 216704 216704 276702 276702 277043 277043 279595 279595 3056...
result:
ok Minimal imbalance is 71459
Test #11:
score: 0
Accepted
time: 48ms
memory: 5692kb
input:
1000000000 100000 43366 52388 59798 64732 83545 90296 93651 96518 108948 116125 117723 136287 142824 148549 150819 166180 212247 219196 232566 240175 245719 249847 268918 270244 274579 280579 281630 287075 288837 310333 352501 379088 408527 420992 423438 433780 441930 445186 461742 481610 483437 501...
output:
0 43366 43366 52388 52388 59798 59798 64732 64732 83545 83545 90296 90296 93651 93651 96518 96518 108948 108948 116125 116125 117723 117723 136287 136287 142824 142824 148549 148549 150819 150819 166180 166180 212247 212247 219196 219196 232566 232566 240175 240175 245719 245719 249847 249847 268918...
result:
ok Minimal imbalance is 69674
Test #12:
score: 0
Accepted
time: 46ms
memory: 5708kb
input:
1000000000 100000 859 16443 26041 39093 40232 42927 57255 62982 65646 65743 82046 98650 105881 118156 137616 138932 152665 153210 157351 158576 162315 174381 176862 186878 202710 207484 209207 215144 227450 240723 245533 254405 258204 258230 264973 272941 277526 285536 286094 292720 324584 324887 33...
output:
0 859 859 16443 16443 26041 26041 39093 39093 40232 40232 42927 42927 57255 57255 62982 62982 65646 65646 65743 65743 82046 82046 98650 98650 105881 105881 118156 118156 137616 137616 138932 138932 152665 152665 153210 153210 157351 157351 158576 158576 162315 162315 174381 174381 176862 176862 1868...
result:
ok Minimal imbalance is 53927
Test #13:
score: 0
Accepted
time: 16ms
memory: 5476kb
input:
200000 100000 1 2 5 9 13 14 15 18 20 22 23 25 27 28 31 35 37 41 45 46 48 49 51 56 57 60 61 62 63 65 66 67 70 71 72 75 77 78 80 81 82 85 86 91 92 93 95 97 99 100 101 103 104 106 107 108 109 111 112 114 115 117 118 119 120 121 125 127 128 129 130 133 134 135 138 139 140 141 142 147 148 149 150 153 154...
output:
0 1 1 2 2 5 5 9 9 13 13 14 14 15 15 18 18 20 20 22 22 23 23 25 25 27 27 28 28 31 31 35 35 37 37 41 41 45 45 46 46 48 48 49 49 51 51 56 56 57 57 60 60 61 61 62 62 63 63 65 65 66 66 67 67 70 70 71 71 72 72 75 75 77 77 78 78 80 80 81 81 82 82 85 85 86 86 91 91 92 92 93 93 95 95 97 97 99 99 100 100 101 ...
result:
ok Minimal imbalance is 7
Test #14:
score: 0
Accepted
time: 10ms
memory: 5436kb
input:
200000 100000 9 10 11 13 15 17 19 20 21 22 23 27 28 29 31 32 33 34 37 39 42 43 44 46 47 50 51 52 54 56 58 59 61 62 64 65 67 68 70 71 72 74 75 76 80 82 85 87 88 89 92 93 94 95 97 100 101 104 105 106 107 109 110 111 112 113 114 116 117 122 124 125 128 129 130 133 136 137 139 145 146 147 148 153 157 15...
output:
0 9 9 10 10 11 11 13 13 15 15 17 17 19 19 20 20 21 21 22 22 23 23 27 27 28 28 29 29 31 31 32 32 33 33 34 34 37 37 39 39 42 42 43 43 44 44 46 46 47 47 50 50 51 51 52 52 54 54 56 56 58 58 59 59 61 61 62 62 64 64 65 65 67 67 68 68 70 70 71 71 72 72 74 74 75 75 76 76 80 80 82 82 85 85 87 87 88 88 89 89 ...
result:
ok Minimal imbalance is 8
Test #15:
score: 0
Accepted
time: 15ms
memory: 5408kb
input:
200000 100000 3 4 6 7 12 13 14 16 17 19 20 22 24 28 29 30 32 37 38 39 40 41 43 44 45 48 52 53 54 62 64 67 68 69 70 73 75 79 80 86 89 90 91 92 95 99 100 101 102 106 107 109 110 111 112 113 114 115 119 126 128 129 130 131 132 133 134 135 136 137 139 140 142 145 148 149 151 152 153 154 155 156 157 162 ...
output:
0 3 3 4 4 6 6 7 7 12 12 13 13 14 14 16 16 17 17 19 19 20 20 22 22 24 24 28 28 29 29 30 30 32 32 37 37 38 38 39 39 40 40 41 41 43 43 44 44 45 45 48 48 52 52 53 53 54 54 62 62 64 64 67 67 68 68 69 69 70 70 73 73 75 75 79 79 80 80 86 86 89 89 90 90 91 91 92 92 95 95 99 99 100 100 101 101 102 102 106 10...
result:
ok Minimal imbalance is 9
Test #16:
score: 0
Accepted
time: 16ms
memory: 5408kb
input:
200000 100000 1 2 4 6 9 10 11 13 14 15 17 18 21 22 23 25 26 27 30 31 34 37 38 40 44 48 49 50 52 54 56 59 60 62 63 64 66 68 69 70 73 74 75 76 77 78 79 80 81 82 85 91 92 93 96 97 99 103 104 105 108 111 113 114 118 119 120 122 125 126 128 129 132 134 135 136 137 138 141 142 143 144 145 146 147 148 149 ...
output:
0 1 1 2 2 4 4 6 6 9 9 10 10 11 11 13 13 14 14 15 15 17 17 18 18 21 21 22 22 23 23 25 25 26 26 27 27 30 30 31 31 34 34 37 37 38 38 40 40 44 44 48 48 49 49 50 50 52 52 54 54 56 56 59 59 60 60 62 62 63 63 64 64 66 66 68 68 69 69 70 70 73 73 74 74 75 75 76 76 77 77 78 78 79 79 80 80 81 81 82 82 85 85 91...
result:
ok Minimal imbalance is 7
Test #17:
score: 0
Accepted
time: 15ms
memory: 5660kb
input:
200000 100000 3 6 7 9 10 11 13 16 17 19 21 22 23 24 26 27 29 33 36 39 40 41 42 43 44 45 46 48 49 51 52 57 58 60 61 64 65 66 67 70 71 73 75 76 79 81 82 84 85 89 90 91 94 95 96 97 98 101 103 104 105 106 111 113 120 124 126 132 133 135 140 141 144 146 149 150 151 154 155 156 157 158 161 162 164 168 170...
output:
0 3 3 6 6 7 7 9 9 10 10 11 11 13 13 16 16 17 17 19 19 21 21 22 22 23 23 24 24 26 26 27 27 29 29 33 33 36 36 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 48 48 49 49 51 51 52 52 57 57 58 58 60 60 61 61 64 64 65 65 66 66 67 67 70 70 71 71 73 73 75 75 76 76 79 79 81 81 82 82 84 84 85 85 89 89 90 90 ...
result:
ok Minimal imbalance is 9
Test #18:
score: 0
Accepted
time: 0ms
memory: 4160kb
input:
2 1 1
output:
0 2
result:
ok Minimal imbalance is 0
Test #19:
score: 0
Accepted
time: 89ms
memory: 5688kb
input:
999934479 100000 1347 7016 13646 16374 19258 25729 29070 35355 41999 43931 48141 53449 57471 62160 70011 71302 76850 80099 87156 90531 94830 100986 107127 109682 116557 117400 122935 126876 133002 136999 141021 145873 153443 157968 159027 164692 168204 172909 178889 182471 190653 196019 196899 20187...
output:
0 4670 4670 9340 9340 14010 14010 18680 18680 23350 23350 28020 28020 32690 32690 37360 37360 42030 42030 46700 46700 51370 51370 56040 56040 60710 60710 65380 65380 70050 70050 74720 74720 79390 79390 84060 84060 88730 88730 93400 93400 98070 98070 102740 102740 107410 107410 112080 112080 116750 1...
result:
ok Minimal imbalance is 10703
Test #20:
score: 0
Accepted
time: 82ms
memory: 5404kb
input:
999938652 100000 10872 12876 29327 39905 54962 63774 68095 78723 92667 103162 118715 125653 139032 153559 161457 172997 187452 196302 207806 212033 227157 235734 252930 255857 273858 283859 294767 305386 314251 327619 340534 351036 361521 370216 387250 397101 405113 413617 430570 435277 453829 45923...
output:
0 11095 11095 22190 22190 33285 33285 44380 44380 55475 55475 66570 66570 77665 77665 88760 88760 99855 99855 110950 110950 122045 122045 133140 133140 144235 144235 155330 155330 166425 166425 177520 177520 188615 188615 199710 199710 210805 210805 221900 221900 232995 232995 244090 244090 255185 2...
result:
ok Minimal imbalance is 2747
Test #21:
score: 0
Accepted
time: 84ms
memory: 5404kb
input:
999927360 100000 2777 15328 31200 39979 52649 68523 69247 81294 94805 108866 125092 131743 137506 150523 167769 178287 191991 200932 213245 219533 237155 241318 253312 270831 281458 288670 303989 316622 326818 337655 345316 354786 372518 382283 399600 408565 413618 428562 435378 453307 460485 474419...
output:
0 11422 11422 22844 22844 34266 34266 45688 45688 57110 57110 68532 68532 79954 79954 91376 91376 102798 102798 114220 114220 125642 125642 137064 137064 148486 148486 159908 159908 171330 171330 182752 182752 194174 194174 205596 205596 217018 217018 228440 228440 239862 239862 251284 251284 262706...
result:
ok Minimal imbalance is 2840
Test #22:
score: 0
Accepted
time: 82ms
memory: 5496kb
input:
999973226 100000 8238 22946 33688 42374 55242 66863 81086 93866 98195 113105 122089 138236 144142 163223 168825 180021 193238 211332 222913 231489 243095 261038 270761 282786 290131 298656 319277 329899 341441 348632 367549 370885 388745 403498 416443 426637 439241 451995 462335 473876 479891 498950...
output:
0 11923 11923 23858 23858 35793 35793 47728 47728 59663 59663 71598 71598 83533 83533 95468 95468 107403 107403 119338 119338 131273 131273 143208 143208 155143 155143 167078 167078 179013 179013 190948 190948 202883 202883 214818 214818 226753 226753 238688 238688 250623 250623 262558 262558 274493...
result:
ok Minimal imbalance is 3871
Test #23:
score: 0
Accepted
time: 80ms
memory: 5404kb
input:
999949531 100000 743 6197 10329 16172 19309 23132 26683 33598 37622 39742 43421 48654 51693 57257 59690 65723 69262 74479 77169 82025 87674 89494 95109 97377 102998 107176 111805 117071 121947 123348 128149 132227 136488 142523 144092 150001 152892 156515 163460 165985 168396 173464 179654 181215 18...
output:
0 4207 4207 8414 8414 12621 12621 16828 16828 21035 21035 25242 25242 29449 29449 33656 33656 37863 37863 42070 42070 46277 46277 50484 50484 54691 54691 58898 58898 63105 63105 67312 67312 71519 71519 75726 75726 79933 79933 84140 84140 88347 88347 92554 92554 96761 96761 100968 100968 105175 10517...
result:
ok Minimal imbalance is 11601