답안 #1019162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019162 2024-07-10T14:24:20 Z blackslex 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
408 ms 232560 KB
#include<bits/stdc++.h>

using namespace std;

int q, rc, x, y, c;

struct node {
    int val;
    bool lz;
    node *l, *r;
    node() : val(val), l(nullptr), r(nullptr) {}
    node(int val) : val(val), l(nullptr), r(nullptr) {}
};

typedef node* pnode;
pnode rt = nullptr;

void push (int l, int r, pnode &cur) {
    if (!cur->lz) return;
    cur->val = r - l + 1;
    if (l < r) {
        if (!cur->l) cur->l = new node();
        if (!cur->r) cur->r = new node();
        cur->l->lz = cur->r->lz = 1;
    }
    cur->lz = 0;
}

void upd (int l, int r, pnode &cur, int tl, int tr) {
    if (!cur) cur = new node();
    push(l, r, cur);
    if (l > tr || r < tl) return;
    if (l >= tl && r <= tr) return cur->lz = 1, push(l, r, cur), void();
    int mid = (l + r) >> 1;
    upd(l, mid, cur->l, tl, tr);
    upd(mid + 1, r, cur->r, tl, tr);
    cur->val = (cur->l ? cur->l->val : 0) + (cur->r ? cur->r->val : 0);
}

int qr (int l, int r, pnode cur, int tl, int tr) {
    if (l > tr || r < tl || !cur) return 0;
    push(l, r, cur);
    if (l >= tl && r <= tr) return cur->val;
    int mid = (l + r) >> 1;
    return qr(l, mid, cur->l, tl, tr) + qr(mid + 1, r, cur->r, tl, tr);
}

int main() {
    scanf("%d", &q);
    while (q--) {
        scanf("%d %d %d", &rc, &x, &y);
        if (rc == 2) upd(-1e9, 1e9, rt, x + c, y + c);
        else printf("%d\n", c = qr(-1e9, 1e9, rt, x + c, y + c));
    }
}

Compilation message

apple.cpp: In constructor 'node::node()':
apple.cpp:11:5: warning: 'node::val' is initialized with itself [-Winit-self]
   11 |     node() : val(val), l(nullptr), r(nullptr) {}
      |     ^~~~
apple.cpp: In function 'int main()':
apple.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
apple.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d %d %d", &rc, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp: In constructor 'node::node()':
apple.cpp:11:18: warning: '*<unknown>.node::val' is used uninitialized in this function [-Wuninitialized]
   11 |     node() : val(val), l(nullptr), r(nullptr) {}
      |                  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 14 ms 5416 KB Output is correct
5 Correct 15 ms 6492 KB Output is correct
6 Correct 16 ms 6236 KB Output is correct
7 Correct 16 ms 6492 KB Output is correct
8 Correct 110 ms 47356 KB Output is correct
9 Correct 220 ms 81072 KB Output is correct
10 Correct 279 ms 90292 KB Output is correct
11 Correct 260 ms 97684 KB Output is correct
12 Correct 266 ms 100820 KB Output is correct
13 Correct 262 ms 123260 KB Output is correct
14 Correct 230 ms 124752 KB Output is correct
15 Correct 408 ms 225872 KB Output is correct
16 Correct 402 ms 227468 KB Output is correct
17 Correct 245 ms 129036 KB Output is correct
18 Correct 248 ms 128984 KB Output is correct
19 Correct 406 ms 232536 KB Output is correct
20 Correct 406 ms 232560 KB Output is correct