회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례가 있는지 궁금합니다
18917번 - 수열과 쿼리 38
iamhamster
1년 전
0
해당 코드의 반례가 있는지 궁금합니다
#include <stdio.h> #include <stdlib.h> typedef struct Node { int data; struct Node *left, *right; } Node; int total_sum = 0; int total_XOR = 0; Node* createNode(int data) { Node *newNode = (Node*)malloc(sizeof(Node)); newNode->data = data; newNode->left = newNode->right = NULL; return newNode; } Node* insert(Node* node, int data) { if (node == NULL) return createNode(data); if (data < node->data) node->left = insert(node->left, data); else if (data > node->data) node->right = insert(node->right, data); return node; } Node* minValueNode(Node* node) { Node* current = node; while (current && current->left != NULL) current = current->left; return current; } Node* deleteNode(Node* root, int data) { if (root == NULL) return root; if (data < root->data) root->left = deleteNode(root->left, data); else if (data > root->data) root->right = deleteNode(root->right, data); else { if (root->left == NULL) { Node *temp = root->right; free(root); return temp; } else if (root->right == NULL) { Node *temp = root->left; free(root); return temp; } Node* temp = minValueNode(root->right); root->data = temp->data; root->right = deleteNode(root->right, temp->data); } return root; } void add(Node** root, int x) { *root = insert(*root, x); total_sum += x; total_XOR ^= x; } void delete_element(Node** root, int x) { *root = deleteNode(*root, x); total_sum -= x; total_XOR ^= x; } int main() { int m; scanf("%d", &m); Node* root = NULL; add(&root, 0); for (int i = 0; i < m; i++) { int command, x; scanf("%d", &command); if (command == 1) { scanf("%d", &x); add(&root, x); } else if(command == 2) { scanf("%d", &x); delete_element(&root, x); } else if (command == 3) { printf("%d\n", total_sum); } else if (command == 4) { printf("%d\n", total_XOR); } } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
iamhamster 1년 전
해당 코드의 반례가 있는지 궁금합니다