QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355294#6343. Bitaro's travelzyz070 107ms57444kbC++171.6kb2024-03-16 15:24:062024-03-16 15:24:07

Judging History

你现在查看的是最新测评结果

  • [2024-03-16 15:24:07]
  • 评测
  • 测评结果:0
  • 用时:107ms
  • 内存:57444kb
  • [2024-03-16 15:24:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=2e5+5;
int n,q;
ll x[N];
struct SparseTable{
	ll val[20][N];
	template<typename F>
	void build(F f){
		For(i,1,n){
			val[0][i]=f(i);
		}
		For(j,0,18){
			For(i,2<<j,n){
				val[j+1][i]=max(val[j][i-(1<<j)],val[j][i]);
			}
		}
	}
	int next(int i,ll x){
		if(val[0][i]>x) return i;
		Dec(k,18,0){
			int j=i+(1<<k);
			if(j<=n&&val[k][j]<=x){
				i=j;
			}
		}
		return i+1;
	}
	int prev(int i,ll x){
		if(val[0][i]>x) return i;
		Dec(k,18,0){
			int j=i-(1<<k);
			if(j>=1&&val[k][i-1]<=x){
				i=j;
			}
		}
		return i-1;
	}
}st1,st2;
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	For(i,1,n){
		cin>>x[i];
	}
	x[0]=-1e18;
	x[n+1]=1e18;
	st1.build([](int i){return 2*x[i]-x[i-1];});
	st2.build([](int i){return x[i+1]-2*x[i];});
	cin>>q;
	For($,1,q){
		int s;
		cin>>s;
		int pos=lower_bound(x+1,x+n+1,s)-x;
		if(x[pos]-s>=s-x[pos-1]){
			--pos;
		}
		int l=pos,r=pos,dir=0;
		ll ans=0;
		while(1<l||r<n){
			if(!dir){
				int i=max(1,st1.prev(l,x[r+1]));
				ans+=x[l]-x[i];
				if(r<n){
					ans+=x[r+1]-x[i];
					++r;
				}
				l=i;
			}else{
				int i=min(n,st2.next(r,-x[l-1]-1));
				ans+=x[i]-x[r];
				if(l>1){
					ans+=x[i]-x[l-1];
					--l;
				}
				r=i;
			}
			dir^=1;
		}
		cout<<ans<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6096kb

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:

809906248

result:

wrong answer 1st numbers differ - expected: '809906250', found: '809906248'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 107ms
memory: 57444kb

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:

200098
200098
200098
346046
200098
269768
313076
200098
366120
200098
200098
348433
200098
200098
200098
332141
311760
200098
200098
366459
200098
221124
225466
313243
322095
200098
281351
200098
257342
200098
200098
200098
316285
200098
394056
200098
200098
357928
200098
357158
200098
368006
326207...

result:

wrong answer 1st numbers differ - expected: '200107', found: '200098'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%