QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#302683#6343. Bitaro's travelPentagonal0 133ms64492kbC++148.0kb2024-01-11 06:25:242024-01-11 06:25:24

Judging History

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

  • [2024-01-11 06:25:24]
  • 评测
  • 测评结果:0
  • 用时:133ms
  • 内存:64492kb
  • [2024-01-11 06:25:24]
  • 提交

answer

// #pragma GCC target("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
//#pragma GCC -Wnarrowing

//Template {
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
//IO templates
//Note: use endl only for interactive problems or to debug segfaults; use newl for other problems
#define newl "\n"
#define fastIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define fileIO(x) ifstream fin((str) x + (str) ".in"); ofstream fout((str) x + (str) ".out");
// void fileIO(string x) {}
#define flush() fflush(stdout)
#define interact(n) fflush(stdout); cin >> n; if (n == -1) return 0
#define testcases int tt; cin >> tt; fun (i, tt) solve();

#define edgeIO(m) fun (i, m) {int a, b; cin >> a >> b; addEdges(a, b);}
#define WeightedEdgeIO(m) fun (i, m) {int a, b, c; cin >> a >> b >> c; addWeightedEdges(a, b, c);}
 
//types
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define ld long double
#define str string
#define boolean bool
#define String string
 
//vector
#define pb push_back
#define append push_back
 
//pairs
#define mp make_pair
#define p2 pair<int, int>
#define p3 pair<int, p2>
#define m3(x, y, z) mp(x, mp(y, z))
#define ich first
#define ni second.first
#define sanshi second.second
 
//For loops
#define ahegao(i, a, b) for (int i = a; i < b; i++)
#define baka(i, b, a) for (int i = b; i > a; i--)
#define fun(i, n) for (int i = 1; i <= (n); (i)++)
#define fon(i, n) for (int i = 0; i < (n); (i)++)
#define fur(i, n) for (auto i : (n))
#define oniichan(i, n) for (auto &i : (n))
 
//Sorts
#define sz(aaa) ((signed) aaa.size())
// #define len(aaa) ((signed) aaa.size())
#define all(a) a.begin(), a.end()
#define Sort(a) sort((a).begin(), (a).end())
#define rSort(a) sort((a).rbegin(), (a).rend())
#define clamp(x, y) (x) = min((int) (x), (int) (y))
#define CLAMP(x, y) (x) = max((int) (x), (int) (y))
 
//Other stuff
#define pqueue priority_queue
#define elif else if
#define addEdges(a, b) adj[a].pb(b); adj[b].pb(a)
#define addWeightedEdges(a, b, c) adj[a].pb(mp(b, c)); adj[b].pb(mp(a, c))
// #define find find_by_order
#define printLength(x) if (x < INF) cout << x << newl; else cout << -1 << newl;
// #define printVector(a) fur (i, a) cout << i << ' '; cout << newl;
void printVector(vector<int> DontUseThisName) {
    fur (i, DontUseThisName) cout << i << ' '; cout << newl;
}
void printVector(vector<p2> DontUseThisName) {
    fur (i, DontUseThisName) cout << i.first << ' ' << i.second << newl; cout << newl;
}
void printVector(vector<vector<int>> DontUseThisName) {
    fur (i, DontUseThisName) printVector(i); cout << newl;
}

void pv(int a) {cout << a << newl;}
void pv(int a, int b) {printVector({a, b});}
void pv(int a, int b, int c) {printVector({a, b, c});}
void pv(int a, int b, int c, int d) {printVector({a, b, c, d});}
void pv(int a, int b, int c, int d, int e) {printVector({a, b, c, d, e});}
// void pv(int a, )
// void printVector(vector<char> DontUseThisName) {
//     fur (i, DontUseThisName) cout << i << ' '; cout << newl;
// }
// void printRange(vector<int>::iterator Left, vector<int>::iterator Right) {
//     for (auto i = Left; i < Right; i++) cout << *i << ' ';
//     cout << newl;
// } 
//Constants
const int MOD =  1e9+7; // 998244353
// const int SMALLMOD = 998244353;
const int INF = 9e10+1337;
const ll EXCEED = 2e18+1337;
const ll GRAVITY = 8e18;

//#define vectorIO(n, MikuBondage) fun (j, n) {int i; cin >> i; MikuBondage.pb(i);}
void vectorIO(int n, vector<int> &DontUseThisName) {
    fun (j, n) {int i; cin >> i; DontUseThisName.pb(i);}
}
//#define vector2IO(n, MikuBondage) fun (j, n) {int i, ii; cin >> i >> ii; MikuBondage.pb(mp(i, ii));}
void vector2IO(int n, vector<p2> &DontUseThisName) {
    fun (j, n) {int i, ii; cin >> i >> ii; DontUseThisName.pb(mp(i, ii));}
}

const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
#define shortest_path_queue priority_queue<p2, vector<p2>, greater<p2>>
#define printArray(DontUseThisName, NakedLolisGalore, GenshinImpactClimbing) ahegao (j, NakedLolisGalore, GenshinImpactClimbing + 1) cout << DontUseThisName[j] << ' '; cout << newl;
#define print2dArray(SplitComplexProblemsIntoMultipleParts, ScuteSwarm, GenshinImpactClimbing) fun (i, ScuteSwarm) {fun (j, GenshinImpactClimbing) cout << SplitComplexProblemsIntoMultipleParts[i][j] << ' '; cout << newl;}
//}
// const int MAX = 500005;
const int MAX = 200003;
const int MID = 19;
int n, q, a[MAX], leftSparse[MAX][MID], rightSparse[MAX][MID];

int RMQleft(int l, int r) {
    int j = 1;
    while ((1 << j) < r - l + 1) j++;
    j--;
    // cout << l << newl;
    // cout << 1336;
    // pv(j, l, r - (1 << j) + 1);
    return(max(leftSparse[l][j], leftSparse[r - (1 << j) + 1][j]));
}

int RMQright(int l, int r) {
    int j = 1;
    while ((1 << j) < r - l + 1) j++;
    j--;
    // cout << l << newl;
    // cout << 1336;
    // pv(j, l, r - (1 << j) + 1);
    return(max(rightSparse[l][j], rightSparse[r - (1 << j) + 1][j]));
}

void init() {
    fun (i, n) {
        leftSparse[i][0] = a[i+1] - 2 * a[i];
        
    }
    leftSparse[n+1][0] = EXCEED;
    
    fun (i, n) {
        rightSparse[i][0] = 2 * a[i] - a[i-1];
    }
    rightSparse[0][0] = EXCEED;
    // fun (i, n) cout << rightSparse[i][0] << ' ';
    fun (k, 18) {
        // cout << newl;
        fun (i, n - (1 << k) + 1) {
            leftSparse[i][k] = max(leftSparse[i][k-1], leftSparse[i + (1 << (k - 1))][k-1]);
            rightSparse[i][k] = max(rightSparse[i][k-1], rightSparse[i + (1 << (k - 1))][k-1]);
            // cout << rightSparse[i][k] << ' ';
        }
    }
}

int bsLeft(int x, int l, int r) {
    while (l < r) {
        int mid = (l + r + 1) / 2;
        if (a[mid] <= x) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }
    return l;
}

int bsRight(int x, int l, int r) {
    while (l < r) {
        int mid = (l + r) / 2;
        if (a[mid] >= x) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

int bs1(int x, int y, int l, int r) {
    while (l < r) {
        int mid = (l + r) / 2;
        if (RMQleft(x, mid) >= a[y]) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

int bs2(int x, int y, int l, int r) {
    while (l < r) {
        
        int mid = (l + r + 1) / 2;
        // pv(l, mid, r);
        if (RMQright(x, mid) > a[y]) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }
    return l;
}


int query(int x) {
    int l = -1, r = -1, curr = -1, res = 0;
    int lll = bsLeft(x, 0, n+1);
    int rrr = bsRight(x, 0, n+1);
    if (x - a[lll] <= a[rrr] - x) {
        l = lll;
        r = lll;
        curr = lll;
        res = x - a[lll];
    } else {
        l = rrr;
        r = rrr;
        curr = lll;
        res = a[rrr] - x;
    }
    while (true) {
        // pv(l, r, res);
        // cout << endl;
        if (r == n or l == 1) {
            return res + a[n] - a[1];
        }
        if (a[l] - a[l-1] <= a[r+1] - a[r]) {
            int nextL = bs2(l, r+1, 0, l);
            res += a[r] - a[nextL];
            l = nextL;
            // cout << nextL << endl;
            assert(a[l] - a[l-1] > a[r+1] - a[r]);
        } else {
            int nextR = bs1(r, l-1, r, n);
            res += a[nextR] - a[l];
            r = nextR;
            assert(a[l] - a[l-1] <= a[r+1] - a[r]);
        }
    }
    
}

signed main() {
    fastIO;
    cin >> n;
    fun (i, n) cin >> a[i];
    a[0] = -INF;
    a[n+1] = INF;
    init();
    cin >> q;
    fun (i, q) {
        int a; cin >> a;
        cout << query(a) << newl;
    }
} 

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 2ms
memory: 7852kb

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: -5
Wrong Answer
time: 1ms
memory: 5844kb

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:

1035633552

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 30
Accepted
time: 132ms
memory: 64384kb

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: 0
Accepted
time: 133ms
memory: 64352kb

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: 0
Accepted
time: 129ms
memory: 64384kb

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: 0
Accepted
time: 126ms
memory: 64380kb

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: 0
Accepted
time: 127ms
memory: 64384kb

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: 0
Accepted
time: 130ms
memory: 64492kb

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
Accepted
time: 14ms
memory: 5556kb

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
237614366
115943118
686592...

result:

ok 200000 numbers

Test #38:

score: 0
Accepted
time: 18ms
memory: 7580kb

input:

1
73
200000
0
1000000000
10
72
125
39
37
127
54
106
35
45
65
95
80
77
45
50
6
54
43
102
2
97
92
59
65
15
16
6
97
31
15
102
110
95
68
0
72
36
101
143
94
97
142
19
15
70
145
22
41
7
35
51
78
141
13
4
143
49
34
37
134
132
14
24
111
19
1
31
113
96
106
34
74
74
27
31
37
96
84
62
47
34
33
133
15
78
120
72...

output:

73
999999927
63
1
52
34
36
54
19
33
38
28
8
22
7
4
28
23
67
19
30
29
71
24
19
14
8
58
57
67
24
42
58
29
37
22
5
73
1
37
28
70
21
24
69
54
58
3
72
51
32
66
38
22
5
68
60
69
70
24
39
36
61
59
59
49
38
54
72
42
40
23
33
39
1
1
46
42
36
23
11
11
26
39
40
60
58
5
47
1
38
7
14
51
73
46
61
8
45
59
33
51
70...

result:

ok 200000 numbers

Test #39:

score: -30
Wrong Answer
time: 126ms
memory: 64380kb

input:

200000
67 98 181 270 354 429 496 561 572 671 696 787 856 935 1022 1065 1091 1129 1188 1256 1296 1316 1386 1388 1462 1495 1513 1563 1621 1665 1760 1790 1812 1855 1918 1971 1990 2087 2137 2234 2313 2329 2423 2501 2585 2642 2695 2795 2893 2990 3085 3095 3185 3279 3315 3327 3377 3454 3493 3553 3617 3662...

output:

10100896
999999933
14574238
13002253
19727669
11009705
15218711
13678079
18071902
18516120
13910578
13098664
12765541
19245270
18563620
19531507
17598566
16639075
18337352
14028651
11260968
14138243
18288313
14125110
18034945
17514062
15950989
17179910
10723293
17833318
17175872
16182912
17058697
17...

result:

wrong answer 38th numbers differ - expected: '18692323', found: '11610226'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%