답안 #1079752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079752 2024-08-29T00:43:13 Z Bula 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
317 ms 207948 KB
#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

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(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 10 ms 5108 KB Output is correct
5 Correct 12 ms 6168 KB Output is correct
6 Correct 11 ms 5980 KB Output is correct
7 Correct 11 ms 5928 KB Output is correct
8 Correct 90 ms 44628 KB Output is correct
9 Correct 180 ms 77244 KB Output is correct
10 Correct 189 ms 85332 KB Output is correct
11 Correct 200 ms 91728 KB Output is correct
12 Correct 220 ms 94600 KB Output is correct
13 Correct 185 ms 109972 KB Output is correct
14 Correct 185 ms 111024 KB Output is correct
15 Correct 314 ms 201780 KB Output is correct
16 Correct 285 ms 203344 KB Output is correct
17 Correct 191 ms 114772 KB Output is correct
18 Correct 188 ms 114768 KB Output is correct
19 Correct 299 ms 207832 KB Output is correct
20 Correct 317 ms 207948 KB Output is correct