Use long long.

This commit is contained in:
unlockable
2023-11-05 15:13:10 +08:00
parent cf1e94a5d1
commit b7b8af4811

View File

@@ -5,28 +5,28 @@
// alive. xxx_num denotes the count as the question described.
int ans[200] = {0};
int dead_nodes_num[105] = {0};
long long dead_nodes_num[105] = {0};
int total_dead_nodes = 0;
int target_nodes_num[105] = {0};
long long target_nodes_num[105] = {0};
int total_target_nodes = 0;
struct SeveralContinuedDeadNode {
bool status;
int length; // Caution that when status == dead and length == 1, the node itself is alive.
long long length; // Caution that when status == dead and length == 1, the node itself is alive.
};
struct SearchResult {
int next_ans_pos; // pos in the ans[] array.
int count_in_father_line; // natural count.
long long count_in_father_line; // natural count.
};
SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
SeveralContinuedDeadNode *upper_line, int upper_line_segment_count,
SearchResult find_node(long long target, long long start_num, int next_dead_node_num_ptr,
SeveralContinuedDeadNode *upper_line, long long upper_line_segment_count,
int layer) {
int spawned_node_max_num = start_num - 1;
int segment_count = upper_line_segment_count;
long long spawned_node_max_num = start_num - 1;
long long segment_count = upper_line_segment_count;
SeveralContinuedDeadNode current_line_node[200] = {0};
int current_line_len = 0;
long long current_line_len = 0;
bool all_dead = true;
// Spawing all the nodes in current line
@@ -38,7 +38,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
}
else {
all_dead = false;
int total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
long long total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
next_dead_node_num_ptr < total_dead_nodes) {
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
@@ -70,7 +70,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
if (target <= spawned_node_max_num) {
ans[0] = target;
int natural_pos = -1, num = start_num - 1;
long long natural_pos = -1, num = start_num - 1;
for (int i = 0; i < current_line_len; i++) {
if (current_line_node[i].status == DEAD) {
natural_pos += current_line_node[i].length;
@@ -102,7 +102,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
return SearchResult{1, -1};
}
int natural_count = -1, num = start_num - 1;
long long natural_count = -1, num = start_num - 1;
for (int i = 0; i < current_line_len; i++) {
natural_count += current_line_node[i].length;
if (current_line_node[i].status == ALIVE || current_line_node[i].length == 1) {
@@ -131,10 +131,10 @@ int main() {
}
}
else {
int current_target = 0;
long long current_target = 0;
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
for (int i = 0; i < total_target_nodes; i++) {
scanf("%d", &current_target);
scanf("%lld", &current_target);
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
if (result.count_in_father_line == -1) {
printf("0\n");