# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
576147 |
2022-06-12T11:47:22 Z |
ddy888 |
Snowball (JOI21_ho_t2) |
C++17 |
|
2500 ms |
8516 KB |
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define si second
typedef pair<ll,ll> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 100010;
int n, q;
ll arr[MAXN];
ll ans[MAXN];
vector<pi> ld, rd;
bool look_left(ll x, int i) {
auto ff = lower_bound(ld.begin(), ld.end(), pi(arr[i] - x, 0));
if (ff == ld.end()) return false;
if (i > 1) {
auto ss = lower_bound(rd.begin(), rd.end(), pi(x - arr[i - 1] + 1, 0));
if (ss == rd.end()) return true;
return (ff->si < ss->si);
}
return true;
}
bool look_right(ll x, int i) {
auto ff = lower_bound(rd.begin(), rd.end(), pi(x - arr[i], 0));
if (ff == rd.end()) return false;
if (i < n) {
auto ss = lower_bound(ld.begin(), ld.end(), pi(arr[i + 1] - x + 1, 0));
if (ss == ld.end()) return true;
return (ff->si < ss->si);
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> arr[i];
ld.pb({0, 0});
rd.pb({0, 0});
ll coord = 0;
for (int i = 1; i <= q; ++i) {
ll x; cin >> x;
coord += x;
if (coord < 0) {
if (-coord > ld.back().fi) ld.pb({-coord, i});
} else {
if (coord > rd.back().fi) rd.pb({coord, i});
}
}
arr[0] = arr[1] - ld.back().fi;
arr[n + 1] = arr[n] + rd.back().fi;
for (int i = 1; i <= n; ++i) {
ll lo = arr[i - 1] - 1;
ll hi = arr[i];
ll lx, rx;
while (lo + 1 < hi) {
ll mid = (lo + hi) >> 1ll;
if (look_left(mid, i)) hi = mid;
else lo = mid;
}
lx = hi;
lo = arr[i];
hi = arr[i + 1] + 1;
while (lo + 1 < hi) {
ll mid = (lo + hi) >> 1ll;
if (look_right(mid, i)) lo = mid;
else hi = mid;
}
rx = lo;
ans[i] = rx - lx;
}
for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
480 KB |
Output is correct |
5 |
Correct |
8 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
9 ms |
476 KB |
Output is correct |
16 |
Correct |
10 ms |
452 KB |
Output is correct |
17 |
Correct |
8 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
480 KB |
Output is correct |
5 |
Correct |
8 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
9 ms |
476 KB |
Output is correct |
16 |
Correct |
10 ms |
452 KB |
Output is correct |
17 |
Correct |
8 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
30 ms |
5684 KB |
Output is correct |
21 |
Correct |
30 ms |
5520 KB |
Output is correct |
22 |
Correct |
29 ms |
5424 KB |
Output is correct |
23 |
Correct |
45 ms |
5188 KB |
Output is correct |
24 |
Correct |
177 ms |
5716 KB |
Output is correct |
25 |
Execution timed out |
2528 ms |
8516 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |