제출 #744729

#제출 시각아이디문제언어결과실행 시간메모리
744729pavementBitaro's travel (JOI23_travel)C++17
15 / 100
3094 ms5508 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define mt make_tuple #define int long long using ii = pair<int, int>; using iii = tuple<int, int, int>; int N, Q, X[200005], Y[200005], Z[200005]; int qryY(int l, int r, int k) { for (int i = l; i <= r; i++) { if (Y[i] >= k) return i; } return N + 1; } int qryZ(int l, int r, int k) { for (int i = r; i >= l; i--) { if (Z[i] > k) return i; } return 0; } main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 1; i <= N; i++) { cin >> X[i]; } for (int i = 1; i <= N; i++) { Y[i] = X[i] - 2 * X[i - 1]; Z[i] = 2 * X[i + 1] - X[i]; } cin >> Q; for (int S; Q--; ) { cin >> S; int cur = 0; int pos = lower_bound(X + 1, X + 1 + N, S) - X; int x = (int)-1e16, y = (int)1e16; if (pos <= N) { y = X[pos]; } if (pos > 1) { x = X[pos - 1]; } cur += min(S - x, y - S); if (S - x <= y - S) { S = pos - 1; } else { S = pos; } int l = S, r = S; //~ cout << "@ " << S << '\n'; while (l > 1 || r < N) { // decide which direction int x = (l == 1 ? (int)1e16 : llabs(X[S] - X[l - 1])); int y = (r == N ? (int)1e16 : llabs(X[S] - X[r + 1])); if (x <= y) { // left // find maximum j < l such that // Z[j] > y + X[S] //~ int j = root[0]->qry(1, l - 1, y + X[S]) + 1; int j = qryZ(1, l - 1, y + X[S]) + 1; // l --> j cur += X[S] - X[j]; l = S = j; } else { // right // find minimum j > r such that // Y[j] >= x - X[S] //~ int j = root[1]->qry(r + 1, N, x - X[S]) - 1; int j = qryY(r + 1, N, x - X[S]) - 1; // r --> j cur += X[j] - X[S]; r = S = j; } //~ cout << "@ " << S << ' ' << l << ' ' << r << ' ' << cur << '\n'; } cout << cur << '\n'; } }

컴파일 시 표준 에러 (stderr) 메시지

travel.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...