QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691362 | #6343. Bitaro's travel | L_Hospital_# | 0 | 75ms | 63188kb | C++14 | 2.0kb | 2024-10-31 11:08:19 | 2024-10-31 11:08:20 |
Judging History
answer
#include<bits/stdc++.h>
# define int long long
# define rep(i, j, k) for (int i = j; i <= k; ++i)
using namespace std;
int n, q, x[200005], lg2[200005], sta[20][200005], stb[20][200005];
void buildst()
{
rep(i, 1, n) sta[0][i] = 2 * x[i] - x[i - 1], stb[0][i] = 2 * x[i] - x[i + 1];
rep(p, 1, 18) rep(i, 1, n - (1 << p) + 1) sta[p][i] = max(sta[p - 1][i], sta[p - 1][i + (1 << (p - 1))]), stb[p][i] = min(stb[p - 1][i], stb[p - 1][i + (1 << (p - 1))]);
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> x[i];
buildst();
cin >> q;
rep(i, 1, q)
{
int now, ans = 0; cin >> now;
if (now <= x[1]) {cout << x[n] - now << '\n'; continue;}
if (now >= x[n]) {cout << now - x[1] << '\n'; continue;}
int pos = lower_bound(x + 1, x + n + 1, now) - x;
if (now - x[pos] > x[pos + 1] - now) ++pos;
ans = abs(now - x[pos]), now = x[pos];
int l = pos - 1, r = pos + 1;
while (l > 0 && r <= n)
{
// cerr << l << ' ' << r << endl;
if (now - x[l] <= x[r] - now)
{
if (l == 1) {ans += now - x[1], now = x[1], l = 0; continue;}
int ppp = l;
for (int i = 18; i >= 0; --i) if (ppp > (1 << i) + 1 && sta[i][ppp - (1 << i)] <= x[r]) ppp -= (1 << i);
ans += now - x[ppp - 1], now = x[ppp - 1], l = ppp - 2;
// cerr << "gfdsgfds" << l << endl;
}
else
{
if (r == n) {ans += x[n] - now, now = x[n], r = n + 1; continue;}
int ppp = r;
for (int i = 18; i >= 0; --i) if (ppp + (1 << i) < n && stb[i][ppp] > x[l]) ppp += (1 << i);
ans += x[ppp + 1] - now, r = ppp + 2, now = x[ppp + 1];
// cerr << "qwe" << r << endl;
}
}
if (l > 0) ans += now - x[1]; else ans += x[n] - now;
cout << ans << '\n';
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 40592kb
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:
1619811693
result:
wrong answer 1st numbers differ - expected: '809906250', found: '1619811693'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 75ms
memory: 63188kb
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:
wrong answer 9168th numbers differ - expected: '200113', found: '400181'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%