답안 #974656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974656 2024-05-03T15:14:43 Z hotboy2703 Ants and Sugar (JOI22_sugar) C++14
0 / 100
478 ms 39760 KB
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXQ = 5e5;
const ll INF = 1e18;
ll q,L;
struct query{
    ll t,x,a;
};
query all[MAXQ+100];
struct node{
    ll a[2][2];
    ll border;
};
node operator + (const node &x,const node &y){
    node res;
    for (ll i = 0;i < 2;i ++)for (ll j= 0 ;j < 2;j ++)res.a[i][j] = INF;
    for (ll ix = 0;ix < 2;ix ++){
    for (ll jx = 0;jx < 2;jx ++){
    for (ll iy = 0;iy < 2;iy ++){
    for (ll jy = 0;jy < 2;jy ++){
        res.a[ix][jy] = min(res.a[ix][jy],x.a[ix][jx] + y.a[iy][jy] + x.border*(ix&&iy));
    }
    }
    }
    }
    res.border = y.border;
    return res;
}
node tree[MAXQ*4+100];
ll lazy[MAXQ * 4 + 100];
ll total[MAXQ + 100];
void build(ll id,ll l,ll r){
    if (l == r){
        tree[id].a[0][1] = INF;
        tree[id].a[1][0] = INF;
    }
    else{
        ll mid = (l + r) >> 1;
        build(id<<1,l,mid);
        build(id<<1|1,mid+1,r);
    }
}
void push(ll id,ll v){
    lazy[id]+=v;
    for (ll i = 0;i < 2;i ++)for (ll j = 0;j < 2;j ++)tree[id].a[i][j] = tree[id].a[i][j]+v;
    tree[id].a[0][0] = min(tree[id].a[0][0],0LL);
    tree[id].border -= v;
}
void lz(ll id){
    push(id<<1,lazy[id]);
    push(id<<1|1,lazy[id]);
    lazy[id] = 0;
}

void update1(ll id,ll l,ll r,ll l1,ll r1,ll v){
    if (l > r1 || l1 > r || l1 > r1)return;
    if (l1 <= l && r <= r1){
        push(id,v);
        return;
    }
    lz(id);
    ll mid = (l + r) >> 1;
    update1(id<<1,l,mid,l1,r1,v);
    update1(id<<1|1,mid+1,r,l1,r1,v);
    tree[id] = tree[id<<1] + tree[id<<1|1];
}
void update2(ll id,ll l,ll r,ll i,ll v){
    if (l > i || r < i)return;
    if (l==r){
        total[l] += v;
        tree[id].a[1][1] = - total[l] + lazy[id];
//        cout<<"BRUH "<<tree[id].a[1][1]<<'\n';
        return;
    }
    lz(id);
    ll mid = (l + r) >> 1;
    update2(id<<1,l,mid,i,v);
    update2(id<<1|1,mid+1,r,i,v);
    tree[id] = tree[id<<1] + tree[id<<1|1];
}
void update3(ll id,ll l,ll r,ll i,ll v){
    if (l > i || r < i)return;
    if (l==r){
        lazy[id]+=v;
        tree[id].a[1][1] = - total[l] + lazy[id];
        return;
    }
    lz(id);
    ll mid = (l + r) >> 1;
    update3(id<<1,l,mid,i,v);
    update3(id<<1|1,mid+1,r,i,v);
    tree[id] = tree[id<<1] + tree[id<<1|1];
}
ll val[MAXQ+100];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>q>>L;
    for (ll i = 1;i <= q;i ++){
        cin>>all[i].t>>all[i].x>>all[i].a;
    }
    ll n = 0;
    for (ll i = 1;i <= q;i ++){
        if (all[i].t==1){
            val[++n]=all[i].x;
        }
    }
    sort(val+1,val+1+n);
    n = unique(val+1,val+1+n)-val-1;
    if (n==0){
        for (ll i = 1;i <= q;i ++){
            cout<<0<<'\n';
        }
        return 0;
    }
    build(1,1,n);
    ll sum = 0;
    for (ll i = 1;i <= q;i ++){
        if (all[i].t==1){update2(1,1,n,lower_bound(val+1,val+1+n,all[i].x)-val,all[i].a);sum += all[i].a;}
        else{
            ll l = lower_bound(val+1,val+1+n,all[i].x-L)-val;
            ll r = upper_bound(val+1,val+1+n,all[i].x+L)-val-1;
            if (l <= r){
//                cout<<i<<' '<<l<<' '<<r<<endl;
                update1(1,1,n,l,r-1,all[i].a);
                update3(1,1,n,r,all[i].a);
            }
        }
        ll res = INF;
        for (ll i = 0;i < 2;i ++)for (ll j = 0;j < 2;j ++)res = min(res,tree[1].a[i][j]);
//        for (ll k = 1;k <= 3;k ++){
//            for (ll i = 0;i < 2;i ++)for (ll j = 0;j < 2;j ++)cout<<tree[k].a[i][j]<<' ';
//            cout<<'\n';
//        }
        cout<<sum+res<<'\n';
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 478 ms 39760 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 231 ms 31776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -