#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const ll inf = 1e15;
struct ST{
vector<ll> a;
vector<bool> b;
int n;
ST(int ns){
n = ns;
a.resize(n + 1);
b.resize(n + 1);
}
void upd(int p, ll x){
a[p] = x;
b[p] = 1;
}
void add(int l, int r, int x){
for (int i = l; i <= r; i++){
a[i] += x;
}
}
ll get1(int p){
return a[p];
}
int get2(int p){
int cc = 0;
for (int i = 1; i <= p; i++){
cc += b[i];
}
return cc;
}
};
struct ST1{
vector<ll> a;
int n;
ST1(int ns){
n = ns;
a.assign(n + 1, -inf);
}
void add(int l, int r, int x){
for (int i = l; i <= r; i++){
a[i] += x;
}
}
ll get(){
ll mx = numeric_limits<ll> :: min();
for (int i = 1; i <= n; i++){
mx = max(mx, a[i]);
}
return mx;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// t[j] = xi - xj + d * (j - i)
cout<<fixed<<setprecision(15);
auto print = [&](ll x){
if (x % 2 == 0){
cout<<x / 2<<" ";
}
else {
cout<<(x - 1) / 2<<".5 ";
}
};
int n, m, d; cin>>n>>m>>d;
vector<int> a(n + 1), b(m + 1), all = {0};
for (int i = 1; i <= n; i++){
cin>>a[i];
all.pb(a[i]);
}
for (int i = 1; i <= m; i++){
cin>>b[i];
all.pb(b[i]);
}
sort(all.begin(), all.end());
vector<int> :: iterator it;
map<int, int> cc;
const int N = n + m;
ST T(N); ST1 T1(N);
set<int> st;
vector<int> r(N + 1);
auto add = [&](int x){
it = lower_bound(all.begin(), all.end(), x);
int i = (int) (it - all.begin()) + cc[x]++;
auto it = st.lower_bound(x);
if (it == st.begin()){
T.upd(i, x - d);
st.insert(i);
return;
}
it--;
int j = (*it);
ll y = T.get1(j); int ii = T.get2(i) + 1;
ll v = x - 1LL * ii * d;
T.add(i + 1, N, -d);
if (y < v){
r[i] = max(r[j], i);
T1.add(i + 1, r[j], x - all[j]);
r[j] = i - 1;
while (true){
auto it = st.lower_bound(r[i]);
if (it == st.end()) break;
int k = *it;
if (T.get1(k) <= v){
T1.add(r[i] + 1, k, x - all[k]);
r[i] = k;
st.erase(it);
}
}
st.insert(i);
}
else {
T1.add(i, i, all[j] - x + 1LL * d * (i - j));
r[j] = max(r[j], i);
while (true){
auto it = st.lower_bound(r[j]);
if (it == st.end()) break;
int k = (*it);
if (T.get1(k) <= y){
T1.add(r[j] + 1, k, all[j] - all[k]);
r[j] = k;
st.erase(it);
}
}
}
T.upd(i, v);
};
for (int i = 1; i <= n; i++) add(a[i]);
for (int i = 1; i <= m; i++){
add(b[i]);
print(T1.get());
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1506 ms |
6592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1506 ms |
6592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |