QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790471 | #8157. 刷野 I | LGMaster | 100 ✓ | 17ms | 6280kb | C++14 | 2.1kb | 2024-11-28 12:26:53 | 2024-11-28 12:26:54 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<climits>
#define int long long
#define getchar_unlocked() getchar()
using namespace std;
const int N=1e5+5;
int n,m,a[N],ans,c[N],die,b[N];
inline int lowbit(int x){
return x&-x;
}
void add(int x,int k){
for(;x<=n;x+=lowbit(x)) c[x]+=k;
}
inline int ask(int x){
int ans=0;
for(;x;x-=lowbit(x)) ans+=c[x];
return ans;
}
void add1(int x,int y,int k){
add(x,k),add(y+1,-k);
}
inline int read(){
int s=0,f=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar_unlocked();
}
while(isdigit(ch)){
s=(s<<3)+(s<<1)+(ch&15);
ch=getchar_unlocked();
}
return s*f;
}
signed main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
n=read(),m=read();
for(int i=1;i<=n;i++) a[i]=read();
sort(a+1,a+1+n);
if(m==0){
for(int i=1;i<=n;i++) ans+=(i>1?a[i]:(a[i]-1))*(n-i+1);
printf("%lld",ans);
return 0;
}
for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1],add(i,b[i]);
// cout<<ask(4)<<"\n";
for(int i=1;i<=m;i++){
if(n-die>=3){
add1(die+1,n,-1);
int l=die+1,r=n;
while(l<=r){
int mid=(l+r)/2;
if(ask(mid)>0) r=mid-1;
else l=mid+1;
}
die=r;
// cout<<c[die]<<" "<<die<<" ";
ans+=(n-die);
// cout<<"1 ";
}
else if(n-die==2){
if(ask(die+1)==1){
if(ask(die+2)>1){
add1(die+1,n,-1);
die++,ans++;
continue;
}
add1(die+1,n,-1);
if(ask(die+1)==0) die++;
if(ask(die+1)==0) die++;
// cout<<"2 ";
}
else{
// add(die+1,-2);
c[die+1]-=2;
if(ask(die+1)<=0) die++,ans++;
else ans+=2;
// cout<<"3 ";
}
}
else{
add(die+1,-2);
// c[die+1]-=2;
if(ask(die+1)<=0) die++;
else ans++;
// cout<<"4 ";
}
// cout<<"-----\n result:"<<ans<<"\n"<<" "<<ask(1)<<"\n------\n";
}
// cout<<"QWQ"<<ans<<" "<<die+1<<"\n";
for(int i=die+1;i<=n;i++) ans+=(ask(i)-1)*(n-i+1)+(n-i);
printf("%lld",ans);
return 0;
}
/*
hack
1 5
18600947
18600941
*/
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 0ms
memory: 3748kb
input:
1 5 18600947
output:
18600941
result:
ok 1 number(s): "18600941"
Test #2:
score: 5
Accepted
time: 0ms
memory: 3952kb
input:
2 5 18799902 15232748
output:
49265386
result:
ok 1 number(s): "49265386"
Test #3:
score: 5
Accepted
time: 0ms
memory: 3892kb
input:
5 5 18920127 46750697 22109591 65526310 59440191
output:
507697727
result:
ok 1 number(s): "507697727"
Test #4:
score: 5
Accepted
time: 0ms
memory: 3788kb
input:
5 5 19098333 84609942 82479225 93471674 1982219
output:
596433605
result:
ok 1 number(s): "596433605"
Test #5:
score: 5
Accepted
time: 0ms
memory: 3748kb
input:
5 5 19259307 94771954 70526090 49099805 72204246
output:
743454416
result:
ok 1 number(s): "743454416"
Test #6:
score: 5
Accepted
time: 0ms
memory: 3892kb
input:
5 5 19417513 4941199 30892956 77035169 14746274
output:
280764656
result:
ok 1 number(s): "280764656"
Test #7:
score: 5
Accepted
time: 6ms
memory: 4596kb
input:
99998 0 21994670 27391657 87408256 42113290 51702097 53310819 49913412 21050866 58858598 51025883 48512129 8701016 12500673 9096574 73398758 64515714 37758713 5868700 53993362 64298266 3094809 5632536 52112091 23083855 91633983 51159996 79025258 46535026 87292512 14015666 76760364 18726586 11012258 ...
output:
150160177252323095
result:
ok 1 number(s): "150160177252323095"
Test #8:
score: 5
Accepted
time: 9ms
memory: 4596kb
input:
99997 0 22262353 45817555 57216901 63422640 61915680 41471171 54944710 58028499 10534928 97487473 6394905 99161597 97700839 75387308 17477998 4590968 41517858 13558105 90771739 2932179 64439198 25933807 21265802 29763263 7187936 46215916 71295430 26134706 26540269 63761615 48219858 67362504 40292034...
output:
149359334114200109
result:
ok 1 number(s): "149359334114200109"
Test #9:
score: 5
Accepted
time: 10ms
memory: 4656kb
input:
99996 0 22550784 15184749 2489474 15869062 37235883 28161568 81362555 89230702 30396915 34572587 23063161 39781960 1252064 27071749 33794856 46994591 12279954 70856185 75796566 59687886 89790520 77244757 78853593 93429270 1794458 20452845 39704854 89902829 29740592 37819078 49358251 68619161 8362074...
output:
149225839032093026
result:
ok 1 number(s): "149225839032093026"
Test #10:
score: 5
Accepted
time: 13ms
memory: 6168kb
input:
99996 99995 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 23727279 ...
output:
118128160591363728
result:
ok 1 number(s): "118128160591363728"
Test #11:
score: 5
Accepted
time: 3ms
memory: 6280kb
input:
99996 999 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24084440 24...
output:
120408776039946654
result:
ok 1 number(s): "120408776039946654"
Test #12:
score: 5
Accepted
time: 12ms
memory: 6220kb
input:
100000 100000 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 24612574 2461257...
output:
122564105628600000
result:
ok 1 number(s): "122564105628600000"
Test #13:
score: 5
Accepted
time: 17ms
memory: 6216kb
input:
100000 100000 25727572 76392362 49547151 85827261 97159345 84695840 56871917 88751329 29441922 71960720 82667484 86244248 48213422 52527026 24256127 8790471 62814339 1998789 3780156 41498772 40701823 34942457 7802204 85950459 67478297 34125972 50714478 1611897 37060086 31458142 47110004 60225380 443...
output:
148841869928634722
result:
ok 1 number(s): "148841869928634722"
Test #14:
score: 5
Accepted
time: 13ms
memory: 6216kb
input:
100000 100000 25985255 94808261 19345797 7146611 7362928 72866192 61900448 25728961 8808251 18422309 12860260 76714829 33413588 18807760 40645368 21185725 94250716 9680962 40561301 80135452 2036213 55240960 4633147 92649866 83025017 56861892 42974650 8891578 76327843 81201323 18559497 8851298 337184...
output:
149080482426641214
result:
ok 1 number(s): "149080482426641214"
Test #15:
score: 5
Accepted
time: 17ms
memory: 6092kb
input:
100000 100000 26174210 55931569 82869357 93881815 15011576 63996457 79511421 18851918 79487731 582385 42434841 94564149 26554405 86598310 84866606 1241473 47073958 90443015 63915084 27194079 52279505 13550106 24575930 68410538 12769365 48914101 55251855 47836070 60003237 54671477 85988426 52252968 6...
output:
149163998152595139
result:
ok 1 number(s): "149163998152595139"
Test #16:
score: 5
Accepted
time: 13ms
memory: 6096kb
input:
100000 100000 26373164 44742109 46370149 52954251 22677455 55116721 97122395 39667642 50169978 10432461 72002191 12410700 19695222 54398860 29087844 53627222 27584433 43535069 59571636 74255473 2512797 99549251 72198713 16503978 42500945 13293541 67536292 14453330 71365863 28158863 53407354 95657407...
output:
148883433439625968
result:
ok 1 number(s): "148883433439625968"
Test #17:
score: 5
Accepted
time: 17ms
memory: 6092kb
input:
100000 100000 26572118 33555417 9890942 12029456 30333335 46246985 14743369 60473367 20842225 20272537 1586773 57940020 40516038 22189410 981851 5992970 80404907 24297122 82925419 21314099 52756089 57858396 19821496 92274649 72255294 5342982 7493498 81070590 82721257 29306249 20836283 39051845 20365...
output:
149122391640554694
result:
ok 1 number(s): "149122391640554694"
Test #18:
score: 5
Accepted
time: 17ms
memory: 6148kb
input:
100000 100000 26761073 22368724 73401734 98771892 37989215 37367250 32354343 81289091 91521705 2439845 3471354 75799339 33646855 17659960 45193089 86051487 60908150 5061944 6261970 68372725 2999382 43844773 39764279 40375321 1999642 97405190 19767935 47697850 66403883 2776402 88255211 82446284 49245...
output:
149346056623319098
result:
ok 1 number(s): "149346056623319098"
Test #19:
score: 5
Accepted
time: 17ms
memory: 6216kb
input:
100000 100000 26960027 83509264 36925295 57837096 45645094 28497514 49965317 2094816 62203952 12289921 33045936 93648659 26787672 85450510 89414328 38437235 13728625 85823997 1935753 15434119 53232674 2153919 87387063 16148761 59413990 89454630 32045140 14312343 77769277 3933788 27994139 25840722 78...
output:
149172550553396740
result:
ok 1 number(s): "149172550553396740"
Test #20:
score: 5
Accepted
time: 17ms
memory: 6168kb
input:
100000 100000 27158982 72312572 436087 44589533 53290974 19617778 67586291 22900540 32883431 22129997 62610518 11485210 47608488 53241060 33635566 18482984 94229099 38906051 25272305 90172745 3475966 88143064 7329846 64239433 89168339 53834071 44329577 53259603 89121903 77401174 95423068 41565160 70...
output:
149334496938914070
result:
ok 1 number(s): "149334496938914070"