Submission #1264615

#TimeUsernameProblemLanguageResultExecution timeMemory
1264615nickolasarapidisMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
468 ms327680 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back const long MAXN = 200000; struct node{ int left, right; int sum = 0, lazy = 0; node *left_child = nullptr, *right_child = nullptr; node(int l, int r){ left = l; right = r; } void expand(){ if(!left_child and left != right){ int m = (left + right)/2; left_child = new node(left, m); right_child = new node(m + 1, right); } } void update(int a, int b){ expand(); if(lazy != 0){ sum = right - left + 1; if(left != right){ left_child->lazy = 1; right_child->lazy = 1; } lazy = 0; } if(left > b or right < a) return; if(left >= a and right <= b){ sum = right - left + 1; if(left != right){ left_child->lazy = 1; right_child->lazy = 1; } return; } left_child->update(a, b); right_child->update(a, b); sum = left_child->sum + right_child->sum; return; } int query(int a, int b){ expand(); if(lazy != 0){ sum = right - left + 1; if(left != right){ left_child->lazy = 1; right_child->lazy = 1; } lazy = 0; } if(left > b or right < a) return 0; if(left >= a and right <= b) return sum; return left_child->query(a, b) + right_child->query(a, b); } }; int main(){ node *root = new node(0, 1e9 - 1); int M, C = 0; cin >> M; for(int i = 0; i < M; i++){ int d, x, y; cin >> d >> x >> y; if(d == 2){ root->update(x + C, y + C); } else{ C = root->query(x + C, y + C); cout << C << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...