Submission #919819

# Submission time Handle Problem Language Result Execution time Memory
919819 2024-02-01T17:03:16 Z QioCas Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h> // QioCas

#ifdef LOCAL
#include </home/cas/Cp/Lib/debug.h>
#else
#define console(...) void(202421)
#endif

using namespace std;
using ll = long long;

int Q; 

struct node_t {
    int sum = 0, lz = 0;
    node_t *l = nullptr, *r = nullptr;
};
using pnode = node_t*;

void update_node(pnode& IT, int l, int r) {
    if(!IT) IT = new node_t();
    IT->sum = r - l + 1;
    IT->lz = 1;
}

void push_down(pnode& IT, int l, int r) {
    if(IT->lz == 0) return;
    int mid = (l + r) / 2;
    update_node(IT->l, l, mid);
    update_node(IT->r, mid + 1, r);
    IT->lz = 0;
}

void update(pnode& IT, int l, int r, int s, int t) {
    if(!IT) IT = new node_t();
    if(l > t || r < s) return;
    if(s <= l && r <= t) {
        update_node(IT, l, r);
        return;
    } push_down(IT, l, r);
    int mid = (l + r) / 2;
    update(IT->l, l, mid, s, t);
    update(IT->r, mid + 1, r, s, t);
    IT->sum = IT->l->sum + IT->r->sum;
}

int prod(pnode& IT, int l, int r, int s, int t) {
    if(!IT || l > t || r < s) return 0;
    if(s <= l && r <= t) return IT->sum;
    push_down(IT, l, r);
    int mid = (l + r) / 2;
    return prod(IT->l, l, mid, s, t) + prod(IT->r, mid + 1, r, s, t);
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);

    cin >> Q;

    ll c = 0;

    pnode root = new node_t();
    int L = 1, R = 1e9;

    while(Q--) {
        int op; ll l, r;
        cin >> op >> l >> r;
        l += c; r += c;
        if(op == 2) {
            update(root, L, R, l, r);
        } else {
            int x = prod(root, L, R, l, r);
            cout << x << "\n";
            c += x;
        }
    }
    return 0;
}

////////////////////////////////////////////////////////////////////////////
//  Nhân quả không nợ chúng ta thức gì, cho nên xin đừng oán giận   ////////
//                                   _
//                                _oo0oo_
//                               o8888888o
//                               88” . “88
//                               (| -_- |)
//                               O\  =  /O
//                            ____/'---'\____
//                          .'  \\|     |//  '.
//                         /  \\|||  :  |||//  \
//                        /  _||||| -:- |||||_  \
//                        |   | \\\  -  /'| |   |
//                        | \_|  `\`---'//  |_/ |
//                        \  .-\__ `-. -'__/-.  /
//                      ___`. .'  /--.--\  `. . '___
//                   ."" '<  `.___\_<|>_/___.'  _> \"".
//                  | | :  `- \`. ;`. _/; .'/  /  .' ; |
//                  \  \ `-.   \_\_`. _.' _/_/  -' _.' /
//===================`-.`___`-.__\ \___   /__.-'_.'_.-'===================//
//                                `=--=-'
 
// Đức Phật nơi đây phù hộ code con chạy không Bugs. Nam mô a di đà Phật.
 
//
//                      _.-/`)
//                     // / / )
//                  .=// / / / )
//                 //`/ / / / /
//                // /    `  /
//               ||         /
//              ||         /
//               \\       /
//                ))    .'
//               //     /
//

Compilation message

apple.cpp:90:1: warning: multi-line comment [-Wcomment]
   90 | //                         /  \\|||  :  |||//  \
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -