QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125335#6343. Bitaro's travelpiokemon0 2ms5592kbC++142.6kb2023-07-16 15:58:342023-07-16 16:00:59

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:00:59]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:5592kb
  • [2023-07-16 15:58:34]
  • 提交

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];
    }
    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 = 0LL;
        while(l>1 || r<n){
            if (kier==0){
                int aa = d[r+1];
                if (mnp(1,l) < aa){
                    odp += a[r] - a[1];
                    l = 1;
                    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[r]-a[pocz];
                l = pocz;
                kier = 1;
            }
            else{
                int aa = d[l];
                if (mnp(r+1,n) < aa){
                    odp += a[n] - a[l];
                    r = n;
                    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[l];
                r = pocz;
                kier = 0;
            }
        }
        cout << odp << '\n';
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5592kb

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:

15896320566

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%