QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137855 | #6343. Bitaro's travel | Antekb# | 0 | 152ms | 52972kb | C++14 | 2.0kb | 2023-08-10 18:24:10 | 2024-07-04 01:31:34 |
Judging History
answer
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int K=31, N=2e5+5;
int tab[N];
int prv[N][K], nxt[N][K];
int main(){
int n;
cin>>n;
for(int i=0; i<n; i++){
cin>>tab[i];
if(i>0){
int t=0;
while((1<<t)<tab[i]-tab[i-1])t++;
for(int j=0; j<K; j++){
prv[i][j]=prv[i-1][j];
}
for(int tt=t; tt>=0; tt--)prv[i][tt]=i;
}
}
for(int i=n-2; i>=0; i--){
int t=0;
while((1<<t)<tab[i+1]-tab[i])t++;
for(int j=0; j<K; j++){
nxt[i][j]=nxt[i+1][j];
}
for(int tt=t; tt>=0; tt--)nxt[i][tt]=i;
}
int q;
cin>>q;
while(q--){
int pocz;
cin>>pocz;
int L=lower_bound(tab, tab+n, pocz)-tab;
if(L==n || (L>0 && tab[L-1]+tab[L]>=2*pocz))L--;
int R=L;
ll ans=abs(tab[L]-pocz);
int t=0;
bool czy=(L==n-1);//0-poczatek, 1-koniec
while(L!=0 || R!=n-1){
//cout<<L<<" "<<R<<" "<<ans<<"\n";
while((2<<t)<tab[R]-tab[L])t++;
if(L==0){
assert(czy==0);
ans+=tab[n-1]-tab[0];
break;
}
if(R==n-1){
assert(czy==1);
ans+=tab[n-1]-tab[0];
break;
}
if(czy==0){
if(L!=prv[L][t]){
ans+=tab[L]-tab[prv[L][t]];
L=prv[L][t];
}
else{
if(tab[L]-tab[L-1]<=tab[R+1]-tab[L]){
ans+=tab[L]-tab[L-1];
L--;
}
else{
ans+=tab[R+1]-tab[L];
R++;
czy=1;
}
}
}
else{
if(R!=nxt[R][t]){
ans+=-tab[R]+tab[nxt[R][t]];
R=nxt[R][t];
}
else{
if(tab[R+1]-tab[R]<tab[R]-tab[L-1]){
ans+=tab[R+1]-tab[R];
R++;
}
else{
ans+=tab[R]-tab[L-1];
L--;
czy=0;
}
}
}
}
cout<<ans<<"\n";
}
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 8172kb
input:
2000 154914587 154914588 154914591 154914592 154914594 154914596 154914598 154914599 154914601 154914603 154914608 154914610 154914612 154914615 154914618 154914619 154914621 154914622 154914626 154914627 154914631 154914633 154914636 154914638 154914640 154914641 154914642 154914644 154914645 15491...
output:
809906250
result:
ok 1 number(s): "809906250"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4104kb
input:
2000 356563033 356563037 356563039 356563041 356563043 356563045 356563048 356563050 356563051 356563052 356563054 356563055 356563057 356563060 356563061 356563062 356563065 356563067 356563069 356563074 356563076 356563077 356563079 356563080 356563082 356563085 356563086 356563090 356563091 35656...
output:
722242888
result:
ok 1 number(s): "722242888"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6076kb
input:
2000 24477976 24477978 24477981 24477982 24477986 24477988 24477990 24477992 24477993 24477996 24477998 24477999 24478001 24478002 24478003 24478005 24478007 24478008 24478009 24478011 24478012 24478013 24478015 24478016 24478017 24478019 24478020 24478022 24478024 24478026 24478029 24478031 2447803...
output:
795269579
result:
ok 1 number(s): "795269579"
Test #4:
score: -5
Wrong Answer
time: 0ms
memory: 4064kb
input:
2000 118383953 118383958 118383960 118383964 118383966 118383970 118383971 118383972 118383974 118383976 118383977 118383978 118383979 118383981 118383982 118383983 118383986 118383987 118383989 118383990 118383991 118383993 118383994 118383996 118383998 118383999 118384000 118384002 118384006 11838...
output:
6600
result:
wrong answer 1st numbers differ - expected: '633902161', found: '6600'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 152ms
memory: 52972kb
input:
200000 9 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181...
output:
200107 999999991 202154 346046 379455 269768 313076 381369 366120 265794 363817 348433 342292 260613 302587 332141 311760 281789 345769 366459 218270 221124 225466 313243 322095 332977 281351 224651 257342 259560 206246 231269 316285 371811 394056 382486 202443 357928 359464 357158 354417 368006 326...
result:
wrong answer 3722nd numbers differ - expected: '400118', found: '200020'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%