QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#300362 | #6343. Bitaro's travel | danielkou5855 | 0 | 612ms | 89076kb | C++23 | 2.9kb | 2024-01-08 08:14:06 | 2024-01-08 08:14:07 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <bitset>
#define int long long
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = (int) 1e18;
const int LOG = 25;
// int combine(int x, int y) {
// return max(x, y);
// }
vector<vector<int>> stb;
vector<vector<int>> stc;
vector<int> arr, brr, crr;
int N;
int queryb(int &l, int &r, int &idx) {
int ans = arr[r] - arr[l - 1]; l--; idx = l;
if (idx == 0) {
return ans;
}
for (int i = LOG; i >= 0; i--) {
if (idx - (1 << i) >= 0 && stb[i][idx - (1 << i) + 1] <= arr[r + 1]) {
idx -= (1 << i);
}
}
ans += arr[l] - arr[idx], l = idx;
return ans;
}
int queryc(int &l, int &r, int &idx) {
int ans = arr[r + 1] - arr[l]; r++; idx = r;
if (idx == N - 1) {
return ans;
}
for (int i = LOG; i >= 0; i--) {
if (idx + (1 << i) < N - 2 && stc[i][idx] > arr[l - 1]) {
idx += (1 << i);
}
}
ans += arr[idx] - arr[r], r = idx;
return ans;
}
signed main() {
cin.tie(0) -> sync_with_stdio(false);
cin >> N;
arr.resize(N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
brr.resize(N); crr.resize(N); brr[0] = inf; crr[N - 1] = inf;
for (int i = 1; i < N; i++) {
brr[i] = 2 * arr[i] - arr[i - 1];
}
for (int i = 0; i < N - 1; i++) {
crr[i] = 2 * crr[i] - crr[i + 1];
}
// sparse table
stb.resize(LOG + 1); stc.resize(LOG + 1);
for (int i = 0; i <= LOG; i++) {
stb[i].resize(N); stc[i].resize(N);
}
for (int i = 0; i < N; i++) {
stb[0][i] = brr[i]; stc[0][i] = crr[i];
}
for (int i = 1; i <= LOG; i++) {
for (int j = 0; j + (1 << i) <= N; j++) {
stb[i][j] = max(stb[i - 1][j], stb[i - 1][j + (1 << (i - 1))]);
stc[i][j] = min(stc[i - 1][j], stc[i - 1][j + (1 << (i - 1))]);
}
}
int Q; cin >> Q;
while (Q--) {
int start; cin >> start;
int idx = upper_bound(all(arr), start) - arr.begin();
int ans = 0;
if (idx == N) {
ans = abs(start - arr[N - 1]); idx = N - 1;
} else if (idx == 0) {
ans = abs(start - arr[0]);
} else if (arr[idx] - start < start - arr[idx - 1]) {
ans = abs(arr[idx] - start);
} else {
idx--;
ans = abs(start - arr[idx]);
}
int l = idx, r = idx;
while (!(l == 0 && r == N - 1)) {
// cout << l << " " << r << "\n";
if (l == 0) {
ans += abs(arr[N - 1] - arr[idx]);
r = N - 1;
} else if (r == N - 1) {
ans += abs(arr[idx] - arr[0]);
l = 0;
} else {
// get the direction you jump in
if (arr[idx] - arr[l - 1] <= arr[r + 1] - arr[idx]) {
ans += queryb(l, r, idx);
// cout << l << " " << r << " " << idx << "\n";
} else {
ans += queryc(l, r, idx);
}
}
}
cout << ans << "\n";
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 3768kb
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: 4096kb
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:
722272380
result:
wrong answer 1st numbers differ - expected: '722242888', found: '722272380'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 612ms
memory: 89076kb
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 3722nd numbers differ - expected: '400118', found: '19999899868'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%