QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137807#6343. Bitaro's travelRafi22#Compile Error//C++141.7kb2023-08-10 17:50:582024-07-04 01:30:55

Judging History

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

  • [2024-07-04 01:30:55]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 17:50:58]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double
//#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000000000000007;
int mod=1000000007;
int mod1=998244353;

const int N=200007;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n+2);
    a[0]=-inf;
    for(int i=1;i<=n;i++) cin>>a[i];
    a[n+1]=inf;
    int q;
    cin>>q;
    while(q--)
    {
        int x,ans=0;
        cin>>x;
        int l=lower_bound(all(a),x)-a.begin();
        bool side=0;
        ans+=min(x-a[l],a[l+1]-x);
        if(x-a[l]>a[l+1]-x) l++;
        r=l;
        while(l>1&&r<n)
        {
            if(side)
            {
                for(int i=r+1;i<=n;i++)
                {
                    if(2*a[i]-a[i+1]<=a[l-1])
                    {
                        ans+=a[i]-a[r];
                        ans+=a[i]-a[l];
                        r=i;
                        break;
                    }
                }
            }
            else
            {
                for(int i=l-1;i>0;i--)
                {
                    if(2*a[i]-a[i-1]>a[r+1])
                    {
                        ans+=a[l]-a[i];
                        ans+=a[r]-a[i];
                        l=i;
                        break;
                    }
                }
            }
            side^=1;
        }
        if(side) ans+=a[n]-a[r];
        else ans+=a[l]-a[1];
        cout<<ans<<endl;
    }


    return 0;
}
/*
5
0 5 6 7 9
1
7
*/

Details

answer.code: In function ‘int main()’:
answer.code:40:9: error: ‘r’ was not declared in this scope
   40 |         r=l;
      |         ^