20分,只对了地3个点qwq
查看原帖
20分,只对了地3个点qwq
709380
ttltony楼主2023/3/29 13:17

用了快读

#include <iostream>

using namespace std;

typedef long long ll;

inline int read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}

inline void write(ll x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

int main() {
	int t;
	t = read();
	while (t -- ) {
		int l, r;
		l = read();
		r = read();
		if (l == r) write(l % 2), putchar('\n');
		else {
			int ans = 0;
			while (l % 2) {
				ans ++ ;
				l ++ ;
			}
			while (r % 2) {
				ans ++ ;
				r -- ;
			}
			if (l > r) write(ans), putchar('\n');
			else {
				ans += (r - l) >> 1;
				write(ans);
				putchar('\n');
			}
		}
	}
    return 0;
}
2023/3/29 13:17
加载中...