Submission #1079752

#TimeUsernameProblemLanguageResultExecution timeMemory
1079752BulaMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
317 ms207948 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7, N = 1e9;
struct node{
    node *lc, *rc;
    int s = 0, lz = -1;
    node() : s(0), lz(0), lc(nullptr), rc(nullptr){}
} *rt;
void push(node *&v, int l, int r){
    if(v->lz == -1) return;
    if(v->lc == nullptr) v->lc = new node();
    if(v->rc == nullptr) v->rc = new node();
    int m = (l + r) / 2;
    v->lc->s = v->lz * (m - l + 1);
    v->rc->s = v->lz * (r - m);
    v->lc->lz = v->lz;
    v->rc->lz = v->lz;
    v->lz = -1;
}
void up(node *&v, int l, int r, int L, int R, int x){
    if(l > R || r < L) return;
    if(v == nullptr) v = new node();
    if(L <= l && r <= R){
        v->s = 1LL * (r - l + 1) * x;
        v->lz = x;
        return;
    }
    push(v, l, r);
    int m = (l + r) / 2;
    up(v->lc, l, m, L, R, x);
    up(v->rc, m + 1, r, L, R, x);
    v->s = v->lc->s + v->rc->s;
}
int get(node *&v, int l, int r, int L, int R){
    if(r < L || l > R || v == nullptr) return 0LL;
    if(L <= l && r <= R) return v->s;
    push(v, l, r);
    int m = (l + r) / 2;
    return get(v->lc, l, m, L, R) + get(v->rc, m + 1, r, L, R);
}

main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int tt = 1; //cin >> tt;
    while(tt--){
        int q;
        cin >> q;
        int c = 0;
        while(q--){
            int t, x , y;
            cin >> t >> x >> y;
            if(t == 1){
                c = get(rt, 1, N, x + c, y + c);
                cout << c << '\n';
            }else{
                up(rt, 1, N, x + c, y + c, 1);
            }
        }
    }
}

Compilation message (stderr)

apple.cpp: In constructor 'node::node()':
apple.cpp:7:16: warning: 'node::lz' will be initialized after [-Wreorder]
    7 |     int s = 0, lz = -1;
      |                ^~
apple.cpp:6:11: warning:   'node* node::lc' [-Wreorder]
    6 |     node *lc, *rc;
      |           ^~
apple.cpp:8:5: warning:   when initialized here [-Wreorder]
    8 |     node() : s(0), lz(0), lc(nullptr), rc(nullptr){}
      |     ^~~~
apple.cpp: At global scope:
apple.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...