#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const ll NMAX = 200001;
const int INF = 1e9;
const ll nrbits = 20;
const ll MOD = 998244353;
const int VMAX = 10;
int a[NMAX];
int b[NMAX];
int d, cnt;
unordered_map <int, int> mp;
int lazy[NMAX * 4];
struct Node {
int maxim, minim;
int sol;
} aint[NMAX * 4];
void propaga(int node, int st, int dr) {
if(st != dr) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
aint[node].maxim += lazy[node];
aint[node].minim += lazy[node];
lazy[node] = 0;
}
Node combine(Node a, Node b) {
Node sol = {-INF, INF, 0};
sol.sol = max(a.sol, b.sol);
sol.sol = max(sol.sol, a.maxim - b.minim);
sol.maxim = max(a.maxim, b.maxim);
sol.minim = min(a.minim, b.minim);
return sol;
}
void activate(int node, int st, int dr, int x, int val) {
propaga(node, st, dr);
if(st == dr) {
aint[node].maxim += INF + val;
aint[node].minim -= INF;
aint[node].minim += val;
aint[node].sol = 0;
return;
}
int mid = (st + dr) / 2;
if(x <= mid)
activate(node * 2, st, mid, x, val);
else
activate(node * 2 + 1, mid + 1, dr, x, val);
propaga(node * 2, st, mid);
propaga(node * 2 + 1, mid + 1, dr);
aint[node] = combine(aint[node * 2], aint[node * 2 + 1]);
}
void update(int node, int st, int dr, int a, int b, int val) {
if(a > dr)
return;
propaga(node, st, dr);
if(a <= st && dr <= b) {
lazy[node] += val;
return;
}
int mid = (st + dr) / 2;
if(a <= mid)
update(node * 2, st, mid, a, b, val);
if(b > mid)
update(node * 2 + 1, mid + 1, dr, a, b, val);
propaga(node * 2, st, mid);
propaga(node * 2 + 1, mid + 1, dr);
aint[node] = combine(aint[node * 2], aint[node * 2 + 1]);
}
signed main() {
#ifdef HOME
ifstream cin(".in");
ofstream cout(".out");
#endif // HOME
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i = 0; i < NMAX * 4; i++) {
aint[i].maxim = -INF;
aint[i].minim = INF;
aint[i].sol = 0;
}
int n, i, m, x;
cin >> n >> m >> d;
vector <int> nrm;
for(i = 1; i <= n; i++) {
cin >> a[i];
nrm.push_back(a[i]);
}
for(i = 1; i <= m; i++) {
cin >> b[i];
nrm.push_back(b[i]);
}
sort(nrm.begin(), nrm.end()); /// ESTI RETARD?
int last = -1;
for(auto x : nrm) {
if(x != last) {
cnt++;
}
mp[x] = cnt;
last = x;
}
for(i = 1; i <= n; i++) {
update(1, 1, cnt, mp[a[i]] + 1, cnt, -d);
activate(1, 1, cnt, mp[a[i]], a[i]);
}
for(i = 1; i <= m; i++) {
update(1, 1, cnt, mp[b[i]] + 1, cnt, -d);
activate(1, 1, cnt, mp[b[i]], b[i]);
propaga(1, 1, cnt);
int sol = max(0, aint[1].sol);
cout << sol/2;
if(sol%2) cout << ".5";
cout << " ";
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:98:18: warning: unused variable 'x' [-Wunused-variable]
98 | int n, i, m, x;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
3 ms |
10844 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10908 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
3 ms |
10844 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10908 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
230 ms |
27344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
230 ms |
27344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |