Submission #920114

# Submission time Handle Problem Language Result Execution time Memory
920114 2024-02-02T04:49:10 Z QioCas Monkey and Apple-trees (IZhO12_apple) C++14
100 / 100
318 ms 139620 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 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 3416 KB Output is correct
5 Correct 12 ms 4304 KB Output is correct
6 Correct 12 ms 4184 KB Output is correct
7 Correct 12 ms 4308 KB Output is correct
8 Correct 95 ms 30032 KB Output is correct
9 Correct 190 ms 52304 KB Output is correct
10 Correct 193 ms 57696 KB Output is correct
11 Correct 193 ms 61916 KB Output is correct
12 Correct 211 ms 63824 KB Output is correct
13 Correct 192 ms 74320 KB Output is correct
14 Correct 191 ms 75004 KB Output is correct
15 Correct 304 ms 135520 KB Output is correct
16 Correct 318 ms 136520 KB Output is correct
17 Correct 193 ms 77572 KB Output is correct
18 Correct 200 ms 77596 KB Output is correct
19 Correct 306 ms 139620 KB Output is correct
20 Correct 307 ms 139484 KB Output is correct