Submission #37729

#TimeUsernameProblemLanguageResultExecution timeMemory
3772914kgMonkey and Apple-trees (IZhO12_apple)C++11
100 / 100
73 ms1112 KiB
#include <stdio.h> #include <algorithm> #define NN 1073741824 #define min2(x,y) (x<y?x:y) #define max2(x,y) (x>y?x:y) using namespace std; struct TREE { int num; bool check; TREE *left, *right; } *top; void check_node(TREE *node, int len) { if (node->left == NULL) { node->left = (TREE*)malloc(sizeof(TREE)); node->left->left = node->left->right = NULL; node->left->num = node->check ? len : 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->num = node->check ? len : 0; node->right->check = node->check; } } 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->check) return min2(y, r) - max2(l, x) + 1; check_node(node, mid - l + 1); 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 (node->check) return; if (x <= l && r <= y) { node->num = r - l + 1; node->check = true; node->left = node->right = NULL; return; } if (r < x || y < l) return; check_node(node, mid - l + 1); 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; top= (TREE*)malloc(sizeof(TREE)); top->check = false, top->num = 0; top->left = top->right = 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)

apple.cpp: In function 'int main()':
apple.cpp:61:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &k);
                 ^
apple.cpp:63:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &s, &x, &y);
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...