QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691377#6343. Bitaro's travelL_Hospital_#0 79ms57488kbC++142.1kb2024-10-31 11:12:502024-10-31 11:12:51

Judging History

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

  • [2024-10-31 11:12:51]
  • 评测
  • 测评结果:0
  • 用时:79ms
  • 内存:57488kb
  • [2024-10-31 11:12:50]
  • 提交

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()
{
//	freopen("ex.in", "r", stdin);
//	freopen("c.out", "w", stdout);
	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 = upper_bound(x + 1, x + n + 1, now) - x - 1; //cerr << pos << endl;
	    if (now - x[pos] > x[pos + 1] - now) ++pos;
        ans = abs(now - x[pos]), now = x[pos];
        int l = pos - 1, r = pos + 1;
   //     cerr << l << ' ' << r << endl;
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 40468kb

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: 3ms
memory: 38436kb

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: 0
Wrong Answer
time: 79ms
memory: 57488kb

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 133720th numbers differ - expected: '400097', found: '200199'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%