QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137740 | #6343. Bitaro's travel | konstantys# | 0 | 51ms | 8640kb | C++14 | 3.0kb | 2023-08-10 17:12:38 | 2024-07-04 01:30:26 |
Judging History
answer
#include<iostream>
#include<cstdlib>
#include<cstdio>
#define l 524288
using namespace std;
int n,q,tab[200005],a,t[200005][2];
int dp[2*l+5][2];
int pierwszylewo(int a,int x){ //szukamy pierwszego >=x
a^=l;
while(true){
if(a&1){
if(dp[a^1][0]>=x){
a^=1;
break;
}
}
a>>=1;
if(a==1) return 1;
}
//cerr<<"A ";
while(true){
if(a&l) return (a^l)+1;
a<<=1;
if(dp[a^1][0]>=x) a^=1;
}
//cerr<<"B\n";
}
int pierwszyprawo(int a,int x){ //szukamy pierwszego <=x
if(a!=1){
a-=2;
a^=l;
while(true){
if(!(a&1)){
if(dp[a^1][1]<=x){
a^=1;
break;
}
}
a>>=1;
if(a==1) return n;
}
}else{
if(dp[1][1]>x) return n;
}
while(true){
if(a&l) return (a^l)+1;
a<<=1;
if(dp[a][1]>x) a^=1;
}
}
long long wyn[200005];
int main(){
srand(time(NULL));
ios_base::sync_with_stdio(0);
cin>>n;
//n=200000;
for(int i=1;i<=n;i++){
cin>>tab[i];
//tab[i]=i*(1000000000/n);
//tab[i]=tab[i-1]+1+rand()%(1000000000-(n-i)-tab[i-1]);
//cerr<<tab[i]<<"\n";
}
tab[0]=-1000000001;
tab[n+1]=2000000001;
t[1][0]=n;
t[n][1]=1;
dp[1+l-1][0]=t[1][0];
dp[n+l-1][1]=t[n][1];
for(int i=2;i<=n;i++){
t[i][0]=i;
while(tab[t[i][0]+1]-tab[i]<tab[i]-tab[i-1]) t[i][0]++;
dp[i+l-1][0]=t[i][0];
}
for(int i=n-1;i>=1;i--){
t[i][1]=i;
while(tab[i]-tab[t[i][1]-1]<=tab[i+1]-tab[i]) t[i][1]--;
dp[i+l-1][1]=t[i][1];
}
cin>>q;
for(int i=0;i<q;i++){
cin>>a;
cout<<"0\n";
}
return 0;
for(int i=n+1;i<=l;i++) dp[i+l-1][1]=1000000;
for(int i=l-1;i>=1;i--){
dp[i][0]=max(dp[i<<1][0],dp[(i<<1)^1][0]);
dp[i][1]=min(dp[i<<1][1],dp[(i<<1)^1][1]);
}
for(int i=1;i<=n;i++){
int p=i,k=i,s;
wyn[i]=0;
while(true){
s=pierwszylewo(p,k+1);
wyn[i]+=tab[p]-tab[s];
if(k==n)
break;
k++;
p=s;
wyn[i]+=tab[k]-tab[s];
s=pierwszyprawo(k,p-1);
wyn[i]+=tab[s]-tab[k];
if(p==1)
break;
p--;
k=s;
wyn[i]+=tab[s]-tab[p];
}
//cerr<<wyn[i]<<" ";
}
q=200000;
for(int i=0;i<q;i++){
//cin>>a;
a=rand()%1000000001;
//a-=off;
int p=1,k=n,s,y=n+1;
while(k>=p){
s=(p+k)>>1;
if(tab[s]>=a){
k=s-1;
y=s;
}else p=s+1;
}
if(tab[y]-a<a-tab[y-1]){
cout<<wyn[y]+tab[y]-a<<"\n";
}else cout<<wyn[y-1]+a-tab[y-1]<<"\n";
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7720kb
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:
0
result:
wrong answer 1st numbers differ - expected: '809906250', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 51ms
memory: 8640kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '200107', found: '0'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%