This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define x first
#define y second
struct Data{
ll l, r, w, t;
bool operator < (const Data &t) const{
if(l != t.l) return l < t.l;
else return r < t.r;
}
};
ll N, K, M;
pair<ll, ll> P[5005];
Data V[5005];
ll ans = 0;
void dnc(ll l, ll r, ll s){
if(l > r) return;
ll mn = 1e9, idx = 0;
ll ok = 0;
for(int i = l; i <= r; i++){
if(mn > V[i].w) mn = V[i].w, idx = i;
if(V[i].t == 1) ok = 1;
}
if(ok){
ans -= (mn - s) * (V[r].r - V[l].l);
dnc(l, idx - 1, mn);
dnc(idx + 1, r, mn);
} else {
return;
}
}
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N;
for(int i = 1; i <= N; i++){
cin >> P[i].x >> P[i].y;
if(i % 2 == 1 && i != 1){
V[i / 2] = {P[i - 1].x, P[i].x, P[i].y, 0};
ans += (P[i].y) * (P[i].x - P[i - 1].x);
M++;
}
}
cin >> K;
for(int i = 1; i <= K; i++){
ll a, b, c, d; cin >> a >> b >> c >> d;
Data t = {a, c, b};
ll idx = lower_bound(V + 1, V + M + 1, t) - V;
V[idx].t = 1;
}
dnc(1, M, 0);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |