답안 #37688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37688 2017-12-27T02:10:19 Z 14kg 원숭이와 사과 나무 (IZhO12_apple) C++11
0 / 100
456 ms 262144 KB
#include <stdio.h>
#include <algorithm>
#define NN 1073741824

using namespace std;
struct TREE {
	int num;
	bool check;
	TREE *left, *right;
} *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->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->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) {
		node->num = r - l + 1;
		node->check = true;
		node->left = node->right = NULL;
		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->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->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;

	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

apple.cpp: In function 'int main()':
apple.cpp:66:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &k);
                 ^
apple.cpp:68: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);
                                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1112 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 1112 KB Output is correct
4 Correct 19 ms 9824 KB Output is correct
5 Correct 36 ms 12200 KB Output is correct
6 Correct 26 ms 11936 KB Output is correct
7 Correct 39 ms 12200 KB Output is correct
8 Correct 169 ms 98528 KB Output is correct
9 Correct 303 ms 203336 KB Output is correct
10 Correct 366 ms 206372 KB Output is correct
11 Correct 409 ms 211124 KB Output is correct
12 Correct 369 ms 212840 KB Output is correct
13 Correct 336 ms 166904 KB Output is correct
14 Correct 369 ms 167696 KB Output is correct
15 Memory limit exceeded 456 ms 262144 KB Memory limit exceeded
16 Halted 0 ms 0 KB -