#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define vct vector
#define pii pair<int, int>
#define fir first
#define sec second
const int N = 2e5 + 5, M = 2e5 + 5, INF = 1e18;
int n, m, d;
arr<int, N + M> ps;
arr<int, N + M> ind, rv_ind, vl;
struct Rng {
int l, r, mn, mx;
bool operator<(Rng oth) const {
if (l == oth.l && r == oth.r) assert(false);
if (l == oth.l) return r < oth.r;
return l < oth.l;
}
};
int gt_ans(int lst) {
vct<pii> ord;
for (int i = 1; i <= lst; i++)
ord.push_back({ps[i], i});
sort(ord.begin(), ord.end());
fill(ind.begin(), ind.end(), 0);
fill(vl.begin(), vl.end(), 0);
fill(rv_ind.begin(), rv_ind.end(), 0);
for (int i = 0; i < ord.size(); i++) {
ind[ord[i].sec] = i + 1, rv_ind[i + 1] = ord[i].sec;
vl[i + 1] = ord[i].fir - i * d;
}
Rng rng = {0, 0, INF, -INF};
long double ans = 0;
for (int i = 1; i <= n + m; i++) {
if (rv_ind[i] == 0) continue;
if (vl[i] > rng.mx) {
if (rng.l != 0) { rng.r = i - 1; }
rng = {i, 0, vl[i], vl[i]};
}
rng.mn = min(rng.mn, vl[i]);
ans = max(ans, (rng.mx - rng.mn) / (long double) 2);
}
return 2 * ans;
}
signed main() {
// freopen("ms.in", "r", stdin);
cin >> n >> m >> d;
for (int i = 1; i <= n + m; i++) cin >> ps[i];
for (int i = n + 1; i <= n + m; i++) {
int tw_ans = gt_ans(i);
if (tw_ans % 2 == 0) cout << tw_ans / 2 << " ";
else cout << tw_ans / 2 << ".5 ";
}
cout << endl;
}
Compilation message
Main.cpp: In function 'long long int gt_ans(long long int)':
Main.cpp:33:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < ord.size(); i++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9820 KB |
Output is correct |
2 |
Correct |
8 ms |
9820 KB |
Output is correct |
3 |
Correct |
8 ms |
9820 KB |
Output is correct |
4 |
Correct |
8 ms |
9820 KB |
Output is correct |
5 |
Correct |
7 ms |
9820 KB |
Output is correct |
6 |
Correct |
7 ms |
9720 KB |
Output is correct |
7 |
Correct |
7 ms |
9776 KB |
Output is correct |
8 |
Correct |
7 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9820 KB |
Output is correct |
2 |
Correct |
8 ms |
9820 KB |
Output is correct |
3 |
Correct |
8 ms |
9820 KB |
Output is correct |
4 |
Correct |
8 ms |
9820 KB |
Output is correct |
5 |
Correct |
7 ms |
9820 KB |
Output is correct |
6 |
Correct |
7 ms |
9720 KB |
Output is correct |
7 |
Correct |
7 ms |
9776 KB |
Output is correct |
8 |
Correct |
7 ms |
9820 KB |
Output is correct |
9 |
Correct |
238 ms |
20544 KB |
Output is correct |
10 |
Correct |
216 ms |
20584 KB |
Output is correct |
11 |
Correct |
152 ms |
20580 KB |
Output is correct |
12 |
Correct |
289 ms |
20528 KB |
Output is correct |
13 |
Correct |
118 ms |
20136 KB |
Output is correct |
14 |
Correct |
171 ms |
20560 KB |
Output is correct |
15 |
Correct |
223 ms |
19896 KB |
Output is correct |
16 |
Correct |
125 ms |
20576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1563 ms |
13304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1563 ms |
13304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |