# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1162245 | with_wageeh | Monkey and Apple-trees (IZhO12_apple) | C++20 | 244 ms | 69164 KiB |
#include <bits/stdc++.h>
using namespace std;
// SparseSegtree is designed for very large ranges (for example up to 1e9)
// but only creates nodes for segments that are updated or queried.
// It supports range "set" updates (assigning a given value to every element in a range)
// and range sum queries.
class SparseSegtree {
private:
// Each node stores:
// - freq: the aggregate value (here, the sum of the segment)
// - lazy: a lazy propagation marker (nonzero means that the node’s segment
// should be updated to that value)
// - left, right: indices in the tree vector for the left and right children.
struct Node {
int freq = 0; // sum of the segment
int lazy = 0; // lazy marker for range-set updates; 0 means no pending update
int left = -1; // index of left child in the tree vector (-1 if not created)
int right = -1; // index of right child (-1 if not created)
};
vector<Node> tree; // the collection of nodes (dynamically allocated as needed)
const int n; // size of the overall range [0, n-1]
int timer = 0; // used to assign indices for new nodes
// Combine two segment values.
// For a sum query, simply add the two values.
inline int comb(int a, int b) {
return a + b;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |