# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37678 | 14kg | Monkey and Apple-trees (IZhO12_apple) | C++11 | 0 ms | 1112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
#define NN 1073741824
using namespace std;
struct TREE {
int num;
bool check;
TREE *left, *right, *up;
} *top;
int f(TREE *node, int l, int r, int x, int y) {
int mid = (l + r) / 2;
if (x <= l && r <= y) return node->num;
if (r < x || y < l) return 0;
if (node->left == NULL) {
node->left = (TREE*)malloc(sizeof(TREE));
node->left->left = node->left->right = NULL;
node->left->up = node;
node->left->num = node->check ? (mid - l + 1) : 0;
node->left->check = node->check;
}
if (node->right == NULL) {
node->right = (TREE*)malloc(sizeof(TREE));
node->right->left = node->right->right = NULL;
node->right->up = node;
node->right->num = node->check ? (mid - l + 1) : 0;
node->right->check = node->check;
}
return f(node->left, l, mid, x, y) + f(node->right, mid + 1, r, x, y);
}
void Push(TREE *node, int l, int r, int x, int y) {
int mid = (l + r) / 2;
if (x <= l && r <= y) {
// printf("Push) %d %d\n", l, r);
node->num = r - l + 1;
node->check = true;
return;
}
if (r < x || y < l) return;
if (node->left == NULL) {
node->left = (TREE*)malloc(sizeof(TREE));
node->left->left = node->left->right = NULL;
node->left->up = node;
node->left->num = node->check ? (mid - l + 1) : 0;
node->left->check = node->check;
}
if (node->right == NULL) {
node->right = (TREE*)malloc(sizeof(TREE));
node->right->left = node->right->right = NULL;
node->right->up = node;
node->right->num = node->check ? (mid - l + 1) : 0;
node->right->check = node->check;
}
Push(node->left, l, mid, x, y);
Push(node->right, mid + 1, r, x, y);
node->num = node->left->num + node->right->num;
}
int main() {
int k, s, x, y, C = 0, temp;
top= (TREE*)malloc(sizeof(TREE));
top->check = false;
top->left = top->right = top->up = NULL;
scanf("%d", &k);
while (k--) {
scanf("%d %d %d", &s, &x, &y);
x += C, y += C;
if (s == 1) {
C = f(top, 1, NN, x, y);
printf("%d\n", C);
}
else {
Push(top, 1, NN, x, y);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |