Submission #479277

# Submission time Handle Problem Language Result Execution time Memory
479277 2021-10-11T06:34:21 Z jhhope1 Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
0 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, C;
const ll MAXN = 1e9;
struct Node{
    ll val;
    ll lazy_set;
    ll l, r;
    Node(ll val, ll lazy_set):val(val),lazy_set(lazy_set),l(-1),r(-1){};
};
struct Seg{
    vector<Node> V;
    Seg(){
        V.emplace_back(0, 0);
    }
    void push_down(ll s, ll e, ll v){
        ll m = (s+e)>>1;
        if(V[v].l == -1){
            V[v].l = V.size();
            V.emplace_back(V[v].lazy_set*(m-s+1), V[v].lazy_set);
        }
        if(V[v].r == -1){
            V[v].r = V.size();
            V.emplace_back(V[v].lazy_set*(e-m), V[v].lazy_set);
        }
    }
    void update(ll s, ll e, ll l, ll r, ll v, ll val){
        if(e<l || r<s){
            return;
        }
        if(l<=s && e<=r){
            V[v].val = val * (e-s+1);
            V[v].lazy_set = val;
            return;
        }
        push_down(s, e, v);
        ll m = (s+e)>>1;
        update(s, m, l, r, V[v].l, val);
        update(m+1, e, l, r, V[v].r, val);
        V[v].val = V[V[v].l].val + V[V[v].r].val;
    }
    ll sum(ll s, ll e, ll l, ll r, ll v){
        if(e<l || r<s){
            return 0;
        }
        if(l<=s && e<=r){
            return V[v].val;
        }
        push_down(s, e, v);
        ll m = (s+e)>>1;
        return sum(s, m, l, r, V[v].l) + sum(m+1, e, l, r, V[v].r);
    }
}S;
ll M;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>M;
    for(ll i=0,t,x,y ; i<M ; i++){
        cin>>t;
        if(t==1){
            cin>>x>>y;
            C = S.sum(1, MAXN, x+C, y+C, 0);
            cout<<C;
        }
        else if(t==2){
            cin>>x>>y;
            S.update(1, MAXN, x+C, y+C, 0, 1);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -