답안 #787549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787549 2023-07-19T09:33:08 Z doowey Measures (CEOI22_measures) C++17
100 / 100
320 ms 26680 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, int> pii;
 
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
const int N = (int)2e5 + 40;
 
vector<pii> P;
vector<ll> p;
 
bool A[N];
 
ll D;
 
struct Node{
    ll res;
    ll i_val;
    ll j_val;
    ll lazy;
};
 
Node T[N * 4 + 100];
 
Node unite(Node A, Node B){
    Node nw;
    nw.res = max(A.res, B.res);
    nw.i_val = max(A.i_val, B.i_val);
    nw.j_val = max(A.j_val, B.j_val);
    nw.res = max(nw.res, B.i_val + A.j_val);
    nw.lazy = 0ll;
    return nw;
}
 
const ll inf = (ll)1e18;
 
void build(int node, int cl, int cr){
    if(cl == cr){
        T[node].i_val = -inf;
        T[node].j_val = -inf;
        return;
    }
    int mid = (cl + cr) / 2;
    build(node * 2, cl, mid);
    build(node * 2 + 1, mid + 1, cr);
    T[node]=unite(T[node*2],T[node*2+1]);
}
 
void push(int node, int cl, int cr){
    if(T[node].lazy == 0) return;
    T[node].i_val += D * 1ll * T[node].lazy;
    T[node].j_val -= D * 1ll * T[node].lazy;
    if(cl != cr){
        T[node*2+1].lazy += T[node].lazy;
        T[node*2].lazy += T[node].lazy;
    }
    T[node].lazy = 0;
}
 
 
 
void set_pos(int node, int cl, int cr, int id){
    push(node, cl, cr);
    if(cl == cr){
        T[node].i_val += inf-P[id].fi+D;
        T[node].j_val += inf+P[id].fi-D;
        T[node].res = 0ll;
        return;
    }
    int mid = (cl + cr) / 2;
  	push(node * 2, cl, mid);
    push(node * 2 + 1, mid + 1, cr);
    if(mid >= id)
        set_pos(node * 2, cl, mid, id);
    else
        set_pos(node * 2 + 1, mid + 1, cr, id);
    T[node] = unite(T[node*2],T[node*2+1]);
}
 
void inc(int node, int cl, int cr, int tl, int tr, int v){
    push(node, cl, cr);
    if(cr < tl || cl > tr) return;
    if(cl >= tl && cr <= tr){
        T[node].lazy = v;
        push(node, cl, cr);
        return;
    }
    int mid = (cl + cr) / 2;
    inc(node * 2, cl, mid, tl, tr, v);
    inc(node * 2 + 1, mid + 1, cr, tl, tr, v);
    T[node]=unite(T[node*2],T[node*2+1]);
}
 
int get_val(int node, int cl, int cr, int id, int m){
    push(node, cl, cr);
    if(cl==cr){
        if(m == 0)
            return T[node].i_val;
        else
            return T[node].j_val;
    }
    int mid = (cl + cr) / 2;
    if(mid >= id)
        return get_val(node * 2, cl, mid, id, m);
    else
        return get_val(node * 2 + 1, mid + 1, cr, id, m);
}
 
int main(){
    fastIO;
    //freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n >> m >> D;
    p.resize(n + m);
    for(int i = 0 ; i < n; i ++ ){
        cin >> p[i];
    }
    for(int i = n ; i < n + m; i ++ ){
        cin >> p[i];
    }
    for(int i = 0 ; i < n + m ; i ++) {
        P.push_back(mp(p[i], i));
    }
    sort(P.begin(), P.end());
    build(1, 0, n + m - 1);
    int id;
    for(int i = 0 ; i < n + m ; i ++ ){
        id = lower_bound(P.begin(), P.end(), mp(p[i], i)) - P.begin();
        set_pos(1, 0, n + m - 1, id);
        inc(1, 0, n + m - 1, id + 1, n + m - 1, +1);
 
        if(i >= n){
            cout << T[1].res / 2ll;
            if(T[1].res % 2 != 0) cout << ".5 ";
            else cout << " ";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 228 ms 23460 KB Output is correct
10 Correct 254 ms 23484 KB Output is correct
11 Correct 140 ms 23504 KB Output is correct
12 Correct 180 ms 23504 KB Output is correct
13 Correct 143 ms 23040 KB Output is correct
14 Correct 150 ms 23384 KB Output is correct
15 Correct 259 ms 22808 KB Output is correct
16 Correct 137 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 22556 KB Output is correct
2 Correct 170 ms 24848 KB Output is correct
3 Correct 152 ms 24860 KB Output is correct
4 Correct 147 ms 22748 KB Output is correct
5 Correct 151 ms 24020 KB Output is correct
6 Correct 145 ms 23144 KB Output is correct
7 Correct 145 ms 24004 KB Output is correct
8 Correct 170 ms 22836 KB Output is correct
9 Correct 142 ms 22696 KB Output is correct
10 Correct 166 ms 25148 KB Output is correct
11 Correct 145 ms 23452 KB Output is correct
12 Correct 151 ms 24480 KB Output is correct
13 Correct 140 ms 22716 KB Output is correct
14 Correct 145 ms 24628 KB Output is correct
15 Correct 177 ms 24484 KB Output is correct
16 Correct 141 ms 22720 KB Output is correct
17 Correct 164 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 22556 KB Output is correct
2 Correct 170 ms 24848 KB Output is correct
3 Correct 152 ms 24860 KB Output is correct
4 Correct 147 ms 22748 KB Output is correct
5 Correct 151 ms 24020 KB Output is correct
6 Correct 145 ms 23144 KB Output is correct
7 Correct 145 ms 24004 KB Output is correct
8 Correct 170 ms 22836 KB Output is correct
9 Correct 142 ms 22696 KB Output is correct
10 Correct 166 ms 25148 KB Output is correct
11 Correct 145 ms 23452 KB Output is correct
12 Correct 151 ms 24480 KB Output is correct
13 Correct 140 ms 22716 KB Output is correct
14 Correct 145 ms 24628 KB Output is correct
15 Correct 177 ms 24484 KB Output is correct
16 Correct 141 ms 22720 KB Output is correct
17 Correct 164 ms 24012 KB Output is correct
18 Correct 233 ms 23076 KB Output is correct
19 Correct 250 ms 26304 KB Output is correct
20 Correct 154 ms 26456 KB Output is correct
21 Correct 180 ms 24456 KB Output is correct
22 Correct 191 ms 24772 KB Output is correct
23 Correct 154 ms 24476 KB Output is correct
24 Correct 236 ms 25084 KB Output is correct
25 Correct 141 ms 24276 KB Output is correct
26 Correct 237 ms 24260 KB Output is correct
27 Correct 238 ms 26680 KB Output is correct
28 Correct 202 ms 24656 KB Output is correct
29 Correct 219 ms 26052 KB Output is correct
30 Correct 227 ms 24124 KB Output is correct
31 Correct 214 ms 26200 KB Output is correct
32 Correct 181 ms 25972 KB Output is correct
33 Correct 320 ms 23832 KB Output is correct
34 Correct 177 ms 25540 KB Output is correct