Submission #1315763

#TimeUsernameProblemLanguageResultExecution timeMemory
1315763khanh_uwuMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
388 ms258552 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<char, int> ii;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const ll  inf = (ll)1e18 + 1;

#define fi first
#define se second
#define pb push_back

struct Node {
    ll val, lazy;
    Node *left, *right;
    Node() {
        val = lazy = 0;
        left = right = nullptr;
    }
};

Node *root = new Node();

void push(Node* &node, int l, int r) {
     if (node->lazy == 0) return;
     int mid = l + r >> 1;

     if (!node->left) node->left = new Node();
     if (!node->right) node->right = new Node();

     node->left->val = (mid - l + 1) * node->lazy;
     node->left->lazy = node->lazy;

     node->right->val = (r - mid) * node->lazy;
     node->right->lazy = node->lazy;

     node->lazy = 0;
}

void update(Node* &node, int l, int r, int u, int v, int val) {
    if (!node) node = new Node();
    if (l > v || r < u) return;
    if (l >= u && r <= v) {
        node->val = (r - l + 1) * val;
        node->lazy = val;
        return;
    }
    push(node, l, r);
    int mid = l + r >> 1;
    update(node->left, l, mid, u, v, val);
    update(node->right, mid + 1, r, u, v, val);

    ll valL = node->left ? node->left->val : 0;
    ll valR = node->right ? node->right->val : 0;

    node->val = valL + valR;
}

ll get(Node* &node, int l, int r, int u, int v) {
    if (!node || l > v || r < u) return 0;
    push(node, l, r);
    if (l >= u && r <= v) return node->val;
    int mid = l + r >> 1;
    return get(node->left, l, mid, u, v) + get(node->right, mid + 1, r, u, v);
}

const int lim = 1e9;
int q;

void inp() {
    cin >> q;
}

void process() {
    int C = 0;
    while(q--) {
        int op, l, r;
        cin >> op >> l >> r;
        l += C;
        r += C;
        if (op == 1) {
            C = get(root, 1, lim, l, r);
            cout << C << '\n';
        }
        else {
            update(root, 1, lim, l, r, 1);
        }
    }
}

int main() {
    if(fopen("f.in", "r")) {
        freopen("f.in", "r", stdin);
        freopen("f.out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    inp();
    process();

    return 0^0;
}

Compilation message (stderr)

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