QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137909#6343. Bitaro's travelRafi22#0 107ms32896kbC++142.8kb2023-08-10 18:57:462024-07-04 01:32:11

Judging History

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

  • [2024-07-04 01:32:11]
  • 评测
  • 测评结果:0
  • 用时:107ms
  • 内存:32896kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 18:57:46]
  • 提交

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=2000000007;
int mod=1000000007;
int mod1=998244353;

const int N=200007,L=18;

int mn[N][L];
int mx[N][L];
int lg[N];

int get_mn(int l,int r)
{
    int k=lg[r-l+1];
    return min(mn[l][k],mn[r-(1<<k)+1][k]);
}
int get_mx(int l,int r)
{
    int k=lg[r-l+1];
    return max(mx[l][k],mx[r-(1<<k)+1][k]);
}

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;
    for(int i=1;i<=n+1;i++)
    {
        mn[i][0]=2*a[i-1]-a[i];
        mx[i][0]=2*a[i]-a[i-1];
    }
    for(int j=1;j<L;j++)
    {
        for(int i=1;i+(1<<j)-1<=n+1;i++)
        {
            mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
            mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
        }
    }
    for(int i=2;i<=n+1;i++) lg[i]=lg[i/2]+1;
    int q;
    cin>>q;
    while(q--)
    {
        int x;
        ll ans=0;
        cin>>x;
        int l=lower_bound(all(a),x)-a.begin();
        ans+=min(a[l]-x,x-a[l-1]);
        if(a[l]-x>=x-a[l-1]) l--;
        int r=l;
        bool side=0;
        while(l>1||r<n)
        {
            if(l==1)
            {
                if(side) ans+=a[n]-a[r];
                else ans+=a[n]-a[l];
                break;
            }
            if(r==n)
            {
                if(side) ans+=a[r]-a[1];
                else ans+=a[l]-a[1];
                break;
            }
            if(side)
            {
                int L=r+1,R=n+1,sr,i;
                while(L<=R)
                {
                    sr=(L+R)/2;
                    if(get_mn(r+1,sr)<=a[l-1])
                    {
                        i=sr;
                        R=sr-1;
                    }
                    else L=sr+1;
                }
                ans+=a[i-1]-a[r];
                ans+=a[i-1]-a[l-1];
                r=i-1;
                l--;
            }
            else
            {
                int L=0,R=l-1,sr,i;
                while(L<=R)
                {
                    sr=(L+R)/2;
                    if(get_mx(sr+1,l)>a[r+1])
                    {
                        i=sr;
                        L=sr+1;
                    }
                    else R=sr-1;
                }
                ans+=a[l]-a[i+1];
                ans+=a[r+1]-a[i+1];
                l=i+1;
                r++;
            }
            side^=1;
        }
        cout<<ans<<endl;
    }


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 5984kb

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:

809906250

result:

ok 1 number(s): "809906250"

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 5780kb

input:

2000
356563033 356563037 356563039 356563041 356563043 356563045 356563048 356563050 356563051 356563052 356563054 356563055 356563057 356563060 356563061 356563062 356563065 356563067 356563069 356563074 356563076 356563077 356563079 356563080 356563082 356563085 356563086 356563090 356563091 35656...

output:

1035634246

result:

wrong answer 1st numbers differ - expected: '722242888', found: '1035634246'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 30
Accepted
time: 91ms
memory: 32784kb

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
346046
379455
269768
313076
381369
366120
265794
363817
348433
342292
260613
302587
332141
311760
281789
345769
366459
218270
221124
225466
313243
322095
332977
281351
224651
257342
259560
206246
231269
316285
371811
394056
382486
202443
357928
359464
357158
354417
368006
326...

result:

ok 200000 numbers

Test #32:

score: 30
Accepted
time: 101ms
memory: 32828kb

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
214953
203176
263561
315480
345760
288169
362438
292732
224749
214412
299705
264321
211653
248956
233685
236984
306911
206078
236282
203851
343753
216241
366274
383291
227991
214501
208691
248280
282497
201835
302961
384269
339680
249381
395777
201468
253356
249808
316046
217202
336...

result:

ok 200000 numbers

Test #33:

score: 30
Accepted
time: 107ms
memory: 32896kb

input:

200000
0 100 101 102 103 104 105 106 107 108 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...

output:

200098
1000000000
200809
332026
340583
320747
327951
280466
335577
392195
262246
384764
279889
296343
206119
282306
382710
389025
369823
307624
382688
379733
319319
266016
316382
273064
390368
312448
210119
335070
205821
256717
233293
235566
200495
327143
380534
281176
293482
211483
317727
234273
21...

result:

ok 200000 numbers

Test #34:

score: 30
Accepted
time: 91ms
memory: 32808kb

input:

200000
9 109 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 182...

output:

200108
999999991
398935
342885
372407
268595
300075
371409
353777
253452
348389
342780
337158
251989
290087
326120
302345
280025
337667
354788
207572
219029
219537
312936
309352
322171
278794
215577
238037
256322
203016
217393
307132
363991
389419
367602
395084
350195
342074
354917
333585
353297
307...

result:

ok 200000 numbers

Test #35:

score: 30
Accepted
time: 80ms
memory: 32784kb

input:

200000
9 109 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 182...

output:

200108
999999991
399468
396515
254881
299064
337551
286690
358899
284471
214726
211350
282076
246510
393082
233179
230206
229157
287918
388371
216198
398026
326810
396152
352980
362859
207997
211382
207339
245208
279636
387108
287348
370846
326052
238182
377891
390157
238807
236535
303642
200314
331...

result:

ok 200000 numbers

Test #36:

score: 30
Accepted
time: 90ms
memory: 32824kb

input:

200000
0 100 102 103 104 105 106 107 108 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...

output:

200099
1000000000
400101
324295
330652
307228
323659
266967
326296
376082
254255
366054
279702
288698
394108
278540
364606
386882
367087
297310
377645
367863
306592
251530
299280
261817
381250
300696
395926
325927
202038
238905
217436
228164
390510
326430
365953
266838
281214
396382
308060
213534
39...

result:

ok 200000 numbers

Test #37:

score: 0
Wrong Answer
time: 23ms
memory: 5648kb

input:

1
752274513
200000
0
1000000000
3062543
353824670
471209108
300038685
972824952
279683767
647873489
455102926
383075404
304797585
248935750
197299138
525182332
495865149
664082073
708206991
86351822
501205423
604244437
984963897
681547274
314559829
730183804
245318283
760613011
309037613
514660147
8...

output:

752274513
247725487
749211970
-398449843
-281065405
-452235828
220550439
-472590746
-104401024
-297171587
-369199109
-447476928
-503338763
-554975375
-227092181
-256409364
-88192440
-44067522
665922691
-251069090
-148030076
232689384
-70727239
-437714684
-22090709
-506956230
8338498
-443236900
-2376...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%