QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118172 | #149. Peru | cjh_hhz | 0 | 61ms | 58768kb | C++14 | 1.6kb | 2023-07-03 10:05:50 | 2024-09-10 16:38:20 |
Judging History
answer
#include "peru.h"
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+10;
typedef long long ll;
const ll inf=1e18;
const ll p=1e9+7;
int n,k,a[N];
ll f[N]; int q[N],l,r;
ll st1[N],st2[N]; int tp1,tp2;
ll mn1[N],mn2[N];
void rebuild()
{
int mid=(tp1+tp2)>>1,s=tp1+tp2;
reverse(st1+1,st1+tp1+1);
for(int i=1;i<=tp2;i++) st1[++tp1]=st2[i];
tp2=0;
for(int i=mid+1;i<=s;i++) st2[++tp2]=st1[i];
tp1=mid; reverse(st1+1,st1+tp1+1);
for(int i=1;i<=tp1;i++) mn1[i]=min(mn1[i-1],st1[i]);
for(int i=1;i<=tp2;i++) mn2[i]=min(mn2[i-1],st2[i]);
}
void push_back(ll w)
{
st2[++tp2]=w;
mn2[tp2]=min(mn2[tp2-1],w);
}
void pop_back()
{
if(!tp2) rebuild();
tp2--;
}
ll cal_min() {return min(mn1[tp1],mn2[tp2]);}
void pop_front()
{
if(!tp1) rebuild();
tp1--;
}
int solve(int N,int K,int* S)
{
//freopen("test.out","w",stdout);
n=N; k=K;
for(int i=1;i<=n;i++) a[i]=S[i-1];
for(int i=1;i<=n;i++) f[i]=inf;
mn1[0]=mn2[0]=inf;
f[0]=0;
a[0]=2e9+1; r=-1;
for(int i=1;i<=n;i++)
{
assert(q[l]<=n);
while(l<=r&&a[i]>=a[q[r]]) pop_back(),r--;
while(l<=r&&i-q[l]>=k) pop_front(),l++;
if(tp1||tp2) pop_back(),push_back(f[q[r]]+a[i]);
q[++r]=i; f[i]=cal_min();
f[i]=min(f[i],f[max(0,i-k)]+a[q[l]]);
push_back(f[i]);
}
int ans=0,pw=1;
for(int i=n;i>=1;i--)
{
f[i]%=p;
int res=1ll*f[i]*pw%p;
ans=1ll*(ans+res)%p;
pw=23ll*pw%p;
}
return ans;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 18
Accepted
time: 0ms
memory: 13988kb
input:
2000 170 1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...
output:
559335223
result:
ok single line: '559335223'
Test #2:
score: 18
Accepted
time: 2ms
memory: 14068kb
input:
2000 100 1019222751 1012312953 1005125581 978875481 967275037 967176717 965763637 960999157 957233281 956958729 953471924 942217905 936256081 925906257 922808341 918616993 918132100 915435367 911342035 909313549 902957201 902119531 900836861 99996937 892982026 884892282 884816596 884102145 883049077...
output:
818524087
result:
ok single line: '818524087'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 14004kb
input:
2000 20 1046023457 988320769 85389793 1819030505 635209701 362287065 747208901 958302681 957423952 1241659175 352880697 545051421 356189641 1678485313 76683576 940812217 995748541 1920846205 80556065 1358698601 483048309 1881187901 639822057 873315653 1157374529 225761262 1271878801 421346861 190846...
output:
381227021
result:
wrong answer 1st lines differ - expected: '722220390', found: '381227021'
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 31
Accepted
time: 9ms
memory: 19816kb
input:
400000 1000 1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...
output:
677928817
result:
ok single line: '677928817'
Test #16:
score: 0
Wrong Answer
time: 13ms
memory: 21840kb
input:
400000 800 1999974677 1999969921 1999965861 1999958493 1999958025 1999951391 1999947061 1999946921 1999944101 1999935101 1999934785 1999933729 1999933327 1999928689 1999921281 224119121 1999917457 1999914027 1999910181 1999903529 1999898241 1999890703 1999885291 1999877461 1999873851 1999865681 1999...
output:
373665512
result:
wrong answer 1st lines differ - expected: '390755425', found: '373665512'
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 51
Accepted
time: 46ms
memory: 57620kb
input:
2500000 2000 1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...
output:
12623259
result:
ok single line: '12623259'
Test #35:
score: 51
Accepted
time: 49ms
memory: 57056kb
input:
2500000 7700 1073053765 1072890026 1072529695 1072496806 1072464253 1072070707 1071776476 1071612499 1071482023 1071252612 1070990956 1070989988 1070924401 1070859816 1070761897 1070728924 1070728609 1070661817 1070367891 1070334353 1069976601 1069910201 1069844167 1069843321 1069778665 1069681476 1...
output:
962647496
result:
ok single line: '962647496'
Test #36:
score: 51
Accepted
time: 50ms
memory: 54388kb
input:
2500000 6000 1073381395 1072824492 1072627993 1072529745 1072529661 1072070887 1071546841 1071513973 1071317878 1071252801 1071187186 1071121456 1071121144 1070827397 1070434807 1070400409 1070268625 1070204353 1069747681 1068895612 1068895333 1068831809 1068796905 1068794865 1068728623 1068602599 1...
output:
24096464
result:
ok single line: '24096464'
Test #37:
score: 51
Accepted
time: 52ms
memory: 54444kb
input:
2500000 5000 1073283086 1073184841 1072627921 1072529745 1071449209 1071448761 1071317962 1070958241 1070957161 1070827433 1070663826 1070629051 1070565499 1070269017 1070236951 1070172027 1070008001 1069942252 1069940852 1069746406 1069681537 1069648801 1069646071 1069615801 1069615582 1069581129 1...
output:
564483941
result:
ok single line: '564483941'
Test #38:
score: 51
Accepted
time: 61ms
memory: 53944kb
input:
2500000 7000 1072726227 1072267661 1071580126 1071579202 1071546789 1071546735 1071252460 1071154671 1071055506 1070827147 1070826901 1070761015 1070531113 1070466564 1070401946 1070269017 1070007022 1069911319 1069778917 1069681212 1069678837 1069322645 1069319161 1069289805 1069123537 1069060771 1...
output:
915281751
result:
ok single line: '915281751'
Test #39:
score: 51
Accepted
time: 46ms
memory: 57208kb
input:
2500000 8333 1072922751 1072791757 1072169368 1071743895 1071743775 1071711106 1071678413 1071678403 1071645597 1071449065 1071416215 1070958351 1070958261 1070663358 1070433751 1070433167 1070402054 1070171677 1070074801 1069616401 1069223977 1069058143 1069028317 1068963022 1068859973 1068830486 1...
output:
889389722
result:
ok single line: '889389722'
Test #40:
score: 51
Accepted
time: 58ms
memory: 58768kb
input:
2500000 6500 1072333131 1072267765 1072201901 1071677621 1071645693 1071645681 1070925545 1070925226 1070891095 1070858496 1070661726 1070466849 1070368953 1070140354 1069942420 1069876081 1069845667 1069713337 1069518101 1069485369 1069452025 1069451785 1069387831 1069289560 1069254109 1069056953 1...
output:
802521424
result:
ok single line: '802521424'
Test #41:
score: 51
Accepted
time: 54ms
memory: 55952kb
input:
2500000 4900 1073512461 1073512459 1072267561 1072103761 1071776116 1071678277 1071448449 1071220159 1071220151 1071089147 1070860168 1070728844 1070301961 1070074161 1069942337 1069877658 1069845733 1069844641 1069744486 1069680036 1069649029 1069548701 1069452175 1069419361 1069322699 1069288912 1...
output:
696343398
result:
ok single line: '696343398'
Test #42:
score: 51
Accepted
time: 39ms
memory: 57724kb
input:
2500000 9000 1072660747 1072398625 1071842121 1071644913 1071121309 1071023153 1070990977 1070859921 1070696353 1070630419 1070565549 1070336173 1070205572 1070204197 1070171523 1070139214 1070107501 1070009326 1069649269 1069517983 1069486110 1069126495 1069124701 1068438289 1068407227 1068401733 1...
output:
402689022
result:
ok single line: '402689022'
Test #43:
score: 51
Accepted
time: 14ms
memory: 31764kb
input:
1000000 6000 1073053717 1071874211 1070499251 1070074920 1069584189 1069483294 1068959057 1068925075 1068467107 1068110724 1067785754 1067589436 1067162017 1066934961 1066729686 1066603721 1066577621 1066381669 1066115761 1066086202 1066054969 1065954801 1065912563 1065823010 1065792157 1065695737 1...
output:
822342391
result:
ok single line: '822342391'
Test #44:
score: 0
Wrong Answer
time: 53ms
memory: 39320kb
input:
1500000 1000 138887169 842158381 854185856 1008551906 558399701 1921232339 595858841 613689679 95865441 1553418063 258787209 1651677551 456413373 1457714199 1114741601 1284973451 1569927577 345997866 1203601905 1659092481 1527605771 1948933841 1168252897 1379268111 218303478 1201952561 1634027741 15...
output:
255645549
result:
wrong answer 1st lines differ - expected: '135817932', found: '255645549'