卡常秘籍

· · 个人记录

Part 1.无危险(共18点)

ios::sync_with_stdio(false)
cin.tie(0)
cout.tie(0)
int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}

void write(int x) {
    if (x < 0) putchar('-'), x *= -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int qpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res *= a;
        a *= a; b >>= 1;
    }
    return res;
}
int gcd(int a, int b) { 
    return b ? gcd(b, a % b) : a; 
}
int lower_bound(int* arr, int n, int target) {
    int l = 0, r = n;
    while (l < r) {
        int mid = (l + r) >> 1;
        if (arr[mid] < target) l = mid + 1;
        else r = mid;
    }
    return l;
}

int upper_bound(int* arr, int n, int target) {
    int l = 0, r = n;
    while (l < r) {
        int mid = l + ((r - l) >> 1);
        (arr[mid] > target) ? r = mid : l = mid + 1;
    }
    return l;
}

Part 2.有风险