#include "cmp.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
int a[4096], b[2][64];
void remember(int n) {
for (int i = 0; i < 4096; i++) {
a[i] = -2;
}
for (int i = 0; i < 64; i++) {
b[0][i] = inf;
b[1][i] = -inf;
}
int x = __builtin_popcount(n);
if (x <= 1 + 12-x) {
for (int i = 0; i <= 11; i++) {
if ((n >> i) & 1) bit_set(i+1);
}
}
else {
bit_set(13);
for (int i = 0; i <= 11; i++) {
if (!((n >> i) & 1)) bit_set(i+1);
}
}
}
void update(int x, int y) {
a[x] = y;
b[0][x/64] = min(b[0][x/64], y);
b[1][x/64] = max(b[1][x/64], y);
}
int compare(int n) {
if (n && a[n-1] == 1 && n+1 < 4096 && a[n+1] == -1) {
update(n, 0);
return 0;
}
for (int i = 0; i < n; i++) {
if (i%64 == 0 && i+63 < n) {
if (b[0][i/64] < 1) {
update(n, -1);
return -1;
}
i += 63;
continue;
}
if (a[i] == -2) continue;
else if (a[i] < 1) {
update(n, -1);
return -1;
}
}
for (int i = 0; i < n; i++) {
if (i%64 == 0 && i+63 < n) {
if (b[1][i/64] > -1) {
update(n, 1);
return 1;
}
i += 63;
continue;
}
if (a[i] == -2) continue;
else if (a[i] > -1) {
update(n, 1);
return 1;
}
}
int inv = bit_get(13);
for (int i = 11; i >= 0; i--) {
int x = bit_get(i+1);
if (inv) x = !x;
int y = (n >> i) & 1;
if (x > y) {
update(n, -1);
return -1;
}
else if (x < y) {
update(n, 1);
return 1;
}
}
update(n, 0);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
449 ms |
82520 KB |
ZERO POINTS: For a=1119 and b=3977, correct answer is 1, got -1 |