the count_less_than int target will overflow!
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
#include <stdio.h>
|
||||
int* stairs = NULL;
|
||||
int stairs[100000] = {0};
|
||||
int M, K, H;
|
||||
long long total = 0;
|
||||
|
||||
int main() {
|
||||
scanf("%d %d %d", &M , &K, &H);
|
||||
stairs = new int[M];
|
||||
// stairs = new int[M];
|
||||
for (int i = 0; i < M ; i++) {
|
||||
scanf("%d", &stairs[i]);
|
||||
}
|
||||
for (int i = 0; i < M; i++) {
|
||||
for (int j = i + 1; j <= i + K && j < M; j++) {
|
||||
if (stairs[j] <= stairs[i] + H && stairs[j] >= stairs[i] - H) {
|
||||
if (stairs[j] <= ((long long)stairs[i]) + H && stairs[j] >= stairs[i] - H) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#define TREE_SIZE 10000
|
||||
#define TREE_SIZE 50000
|
||||
struct TreeNode {
|
||||
int val;
|
||||
int size;
|
||||
@@ -133,7 +133,7 @@ int traverse(int pos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count_less_than(int target, int pos) {
|
||||
int count_less_than(long long target, int pos) {
|
||||
if (pos < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -155,6 +155,7 @@ int count_less_than(int target, int pos) {
|
||||
}
|
||||
return 1 + tree[tree[pos].left].size;
|
||||
}
|
||||
|
||||
int main() {
|
||||
scanf("%d %d %d", &M, &K, &H);
|
||||
int num = 0;
|
||||
@@ -170,7 +171,7 @@ int main() {
|
||||
// tree_root);
|
||||
// }
|
||||
|
||||
total += count_less_than(num + H, tree_root) - count_less_than(num - H - 1, tree_root);
|
||||
total += count_less_than(((long long)num) + H, tree_root) - count_less_than(num - H - 1, tree_root);
|
||||
if (i >= K) {
|
||||
tree_root = delete_node(dequeue(), tree_root);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ H = random.randint(10000, 100000)
|
||||
# M = 10000
|
||||
# K = 1
|
||||
# H = 1
|
||||
arr = list(range(0, M))
|
||||
arr = list(range(2147483647, 2147483647 - M, -1))
|
||||
random.shuffle(arr)
|
||||
# print(arr)
|
||||
with open('fuck.txt', 'w') as f:
|
||||
f.write(str(M)+' '+str(K)+' '+str(H)+'\n')
|
||||
for i in arr:
|
||||
|
||||
@@ -11,4 +11,7 @@ ans: 14
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
||||
|
||||
15 2 2
|
||||
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
|
||||
|
||||
15 20 2
|
||||
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
|
||||
Reference in New Issue
Block a user