QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125368#6343. Bitaro's travelpiokemon0 115ms24652kbC++142.9kb2023-07-16 16:21:052023-07-16 16:21:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 16:21:07]
  • 评测
  • 测评结果:0
  • 用时:115ms
  • 内存:24652kb
  • [2023-07-16 16:21:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr int N = 2e5;
int a[N+9];
int d[N+9];
int maks[N+9][25];

int mnp(int l, int r){
    int dlug = r-l+1;
    int pot = 31-__builtin_clz(dlug);
    return max(maks[l][pot],maks[r-(1<<pot)+1][pot]);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q,b;
    cin >> n;
    a[0] = -1e9+9;
    d[0] = 1e9+9;
    for (int x=1;x<=n;x++){
        cin >> a[x];
        d[x] = a[x]-a[x-1];
    }
    a[n+1] = 2e9;
    d[n+1] = 1e9+9;
    for (int x=0;x<=n+1;x++){
        maks[x][0] = d[x];
    }
    for (int k=1;k<19;k++){
        for (int x=0;x<=n+1;x++){
            maks[x][k] = max(maks[x][k-1],maks[min(n,x+(1<<k)-1)][k-1]);
        }
    }
    cin >> q;
    while(q--){
        cin >> b;
        int pocz,kon,srod;
        pocz = 1;
        kon = n;
        while(pocz<kon){
            srod = (pocz+kon+1)/2;
            if (a[srod]<=b) pocz = srod;
            else kon = srod-1;
        }
        int l,r,kier;
        if (abs(b-a[pocz]) < abs(b-a[pocz+1])){
            l = pocz;
            r = pocz;
        }
        else{
            l = pocz+1;
            r = pocz+1;
        }
        if (abs(b-a[l-1]) < abs(b-a[l+1])){
            kier = 0;
        }
        else{
            kier = 1;
        }
        ll odp = abs(b-a[l]);
        int poprz = l;
        while(l>1 || r<n){
            if (kier==0){
                int aa = a[r+1]-a[l];
                if (mnp(1,l) < aa){
                    odp += a[poprz] - a[1];
                    l = 1;
                    poprz = l;
                    kier = 1;
                    continue;
                }
                pocz = 1;
                kon = l-1;
                while(pocz<kon){
                    srod = (pocz+kon+1)/2;
                    if (mnp(srod,l) < aa) kon = srod-1;
                    else pocz = srod;
                }
                odp += a[poprz]-a[pocz];
                l = pocz;
                poprz = l;
                if (a[l]-a[l-1] >= aa) kier = 1;
                else kier = 0;
            }
            else{
                int aa = a[r]-a[l-1];
                if (mnp(r+1,n) < aa){
                    odp += a[n] - a[poprz];
                    r = n;
                    poprz = r;
                    kier = 0;
                    continue;
                }
                pocz = r+1;
                kon = n;
                while(pocz<kon){
                    srod = (pocz+kon)/2;
                    if (mnp(r+1,srod) < aa) pocz = srod+1;
                    else kon = srod;
                }
                odp += a[pocz]-a[poprz];
                r = pocz;
                poprz = r;
                if (d[r+1] < aa) kier = 0;
                else kier = 1;
            }
        }
        cout << odp << '\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: 2ms
memory: 5764kb

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:

809906500

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 115ms
memory: 24652kb

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
254248
379455
330526
287218
381369
234174
265794
363817
251861
342292
260613
302587
268153
288534
281789
345769
233835
218270
379170
374828
287051
278199
332977
318943
224651
342952
259560
206246
231269
284009
371811
206238
382486
202443
242366
359464
243136
354417
232288
274...

result:

wrong answer 4th numbers differ - expected: '346046', found: '254248'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%