Submission #1191512

#TimeUsernameProblemLanguageResultExecution timeMemory
1191512TsotneSVBitaro's travel (JOI23_travel)C++20
100 / 100
337 ms3648 KiB
#include <bits/stdc++.h> using namespace std; /*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣿⠛⣿⠀⠀⠀⠀⣤⣿⢻⡇⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣿⡛⠀⣤⣿⣿⣤⣤⣿⣿⣤⢸⡇⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀ ⠀⠀⠀⠀⠀⠀⠀⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡗⠀ ⢠⣼⣿⣿⣿⣿⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷ ⢸⣿⣿⡟⠛⠛⢿⣿⣿⣿⣿⣿⣿⣿⣤⣤⣤⣿⣿⣿⣿⣤⣤⣼⣿⣿ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠋ */ #define fi first #define se second #define pb push_back #define ins insert #define sz(a) (int)(a.size()) #define all(x) (x).begin(),(x).end() typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} #define ONLINE_JUDGE #ifndef ONLINE_JUDGE #include "debug.h" #else #define debug(...) #endif //const int mod = 1e9+7; //const int mod = 998244353; const int MAXN=2e5+5; const ll inf=1e9,INF=1e18; int n; void solve(int tc = 0){ cin>>n; vi A(n+1); for(int i=1;i<=n;i++) cin>>A[i]; int q; cin>>q; while(q--) { int x; cin>>x; auto p = lower_bound(1+all(A),x); ll ans = 0; int mr = p - A.begin(),ml = mr - 1; while(ml > 0 and mr <= n) { if(x - A[ml] > A[mr] - x) { // x - A[ml] <= A[mr] - x -> A[mr] >= 2x - A[ml] p = lower_bound(1+all(A),2*x - A[ml]); mr = p - A.begin(); ans += A[mr-1] - x; x = A[mr-1]; } else { // x - A[ml] > A[mr] - x -> A[ml] < 2x - A[mr] p = --lower_bound(1+all(A),2*x - A[mr]); ml = p - A.begin(); ans += x - A[ml+1]; x = A[ml+1]; } } if(ml > 0) ans += x - A[1]; if(mr <= n) ans += A[n] - x; print(ans); } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int tc=1; //cin>>tc; for(int t = 0; t < tc; t++) solve(t); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...