Submission #1313306

#TimeUsernameProblemLanguageResultExecution timeMemory
1313306Zbyszek99Measures (CEOI22_measures)C++20
86 / 100
348 ms25512 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

int n,m;
ll d;
int rel_ind[200011];
ll p[200001];

const int tree_siz = 1024*512-1;

struct segtree
{
    ll max_[tree_siz+1];
    ll add[tree_siz+1];
    segtree()
    {
        rep2(i,1,tree_siz)
        {
            max_[i] = -1e15;
            add[i] = 0;
        }
    }
    void push(int v)
    {
        max_[v*2] += add[v];
        max_[v*2+1] += add[v];
        add[v*2] += add[v];
        add[v*2+1] += add[v];
        add[v] = 0;
    }
    void change_seg(int akt, int p1, int p2, int s1, int s2, ll x)
    {
        if(p2 < s1 || p1 > s2) return;
        if(p1 >= s1 && p2 <= s2)
        {
            add[akt] += x;
            max_[akt] += x;
            return;
        }
        push(akt);
        change_seg(akt*2,p1,(p1+p2)/2,s1,s2,x);
        change_seg(akt*2+1,(p1+p2)/2+1,p2,s1,s2,x);
        max_[akt] = max(max_[akt*2],max_[akt*2+1]);
    }
    ll get_max(int akt, int p1, int p2, int s1, int s2)
    {
        if(p2 < s1 || p1 > s2) return -1e18;
        if(p1 >= s1 && p2 <= s2) return max_[akt];
        push(akt);
        return max(get_max(akt*2,p1,(p1+p2)/2,s1,s2),get_max(akt*2+1,(p1+p2)/2+1,p2,s1,s2));
    }
};

segtree left_tree;
segtree right_tree;
ll ans = 0;

void add_elm(int ind)
{
    right_tree.change_seg(1,0,tree_siz/2,ind+1,n+m,d);
    left_tree.change_seg(1,0,tree_siz/2,ind+1,n+m,-d);
    right_tree.change_seg(1,0,tree_siz/2,ind,ind,1e15-p[ind]);
    left_tree.change_seg(1,0,tree_siz/2,ind,ind,1e15+p[ind]);
    ll m1 = left_tree.get_max(1,0,tree_siz/2,0,ind);
    ll m2 = right_tree.get_max(1,0,tree_siz/2,ind,n+m-1);
  //  cout << m1 << " " << m2 << " " << ind << " add\n";
    ans = max(ans,m1+m2);
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random_start();
    cin >> n >> m >> d;
    vector<pll> vsort;
    rep(i,n)
    {
        ll x;
        cin >> x;
        vsort.pb({x,i});
    }
    rep(i,m)
    {
        ll x;
        cin >> x;
        vsort.pb({x,n+i});
    }
    sort(all(vsort));
    int cur = 0;
    forall(it,vsort)
    {
        p[cur] = it.ff;
        rel_ind[it.ss] = cur++;
    }
    rep(i,n+m)
    {
        add_elm(rel_ind[i]);
        if(i >= n)
        {
            if(ans%2 == 0) cout << ans/2 << " ";
            else cout << ans/2 << ".5 ";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...