제출 #1340423

#제출 시각아이디문제언어결과실행 시간메모리
1340423alhassanm원숭이와 사과 나무 (IZhO12_apple)C++20
0 / 100
2 ms1860 KiB
// 2025/8/10: 911Lil_Marrikh - ECPC-2025 Medalists
#include <bits/stdc++.h>
using namespace std;

// #define int int64_t
#define ll int64_t
#define el "\n"

const int MAX_NODES = 100000 + 5;

template <typename T = int>
struct DynamicSegTree {
    struct Node {
        int ls = 0, rs = 0;
        T sum = 0, lz = 0;
    } t[MAX_NODES];
    int root = 0, tot = 0;

    void push(int u, int l, int r) {
        if (!t[u].lz || l == r) return;
        if (!t[u].ls) t[u].ls = ++tot;
        if (!t[u].rs) t[u].rs = ++tot;
        
        int mid = l + (r - l) / 2, ls = t[u].ls, rs = t[u].rs;
        T lz = t[u].lz;
        
        t[ls].sum = (mid - l + 1); t[ls].lz = true;
        t[rs].sum = (r - mid);     t[rs].lz = true;
        t[u].lz = 0;
    }

    void update(int& u, int l, int r, int ql, int qr) {
        if (!u) u = ++tot;
        if (ql <= l && r <= qr) {
            t[u].sum = (r - l + 1);
            t[u].lz = true;
            return;
        }
        push(u, l, r);
        int mid = l + (r - l) / 2;
        if (ql <= mid) update(t[u].ls, l, mid, ql, qr);
        if (qr > mid)  update(t[u].rs, mid + 1, r, ql, qr);
        t[u].sum = t[t[u].ls].sum + t[t[u].rs].sum;
    }

    T query(int u, int l, int r, int ql, int qr) {
        if (!u || ql > r || qr < l) return 0;
        if (ql <= l && r <= qr) return t[u].sum;
        push(u, l, r);
        int mid = l + (r - l) / 2;
        return query(t[u].ls, l, mid, ql, qr) + query(t[u].rs, mid + 1, r, ql, qr);
    }
};

void work(int tc) {
    DynamicSegTree sg;

    int n; cin >> n;
    int c = 0;
    while (n--) {
        int d, x, y; cin >> d >> x >> y;
        x += c, y += c;
        if (d == 1) {
            c = sg.query(sg.root, 1, 1e9, x, y);
            cout << c << el;
        } else {
            sg.update(sg.root, 1, 1e9, x, y);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
// #ifndef ONLINE_JUDGE
    freopen("f.in", "r", stdin);
    freopen("f.out", "w", stdout);
// #endif

    int _t = 1;
    // cin >> _t;
    for (int i = 1; i <= _t; i++) {
        work(i);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'int main()':
apple.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen("f.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
apple.cpp:78:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     freopen("f.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...