Submission #72757752


Source Code Expand

#include<cstdio>
int q;
long long int l, r;
char res[5001000];
inline int popcount(unsigned long long int x) {
	x ^= x >> 32;
	x ^= x >> 16;
	x ^= x >> 8;
	x ^= x >> 4;
	x ^= x >> 2;
	x ^= x >> 1;
	return x & 1;
}
int main() {
	int tcn = 0;
	scanf("%d", &tcn);
	while (tcn--) {
		scanf("%d%lld%lld", &q, &l, &r);
		long long int ans = (r - l + 2) / 2;
		bool flag = false;
		if (l % 2 == 1 && r % 2 == 0) {
			if (popcount(l) == popcount(r)) {
				ans++;
			}
			else {
				long long int diff = l ^ r;
				int diffbit = 0;
				while (diff > 0) {
					diff >>= 1;
					diffbit++;
				}
				diffbit--;
				long long int diffsize = 1LL << diffbit;
				if (r - l < diffsize) {
					flag = true;
					ans++;
				}
			}
		}
		if (q == 0) {
			printf("%lld\n", ans);
		}
		else {
			if (flag) {
				long long int lpvt = popcount(l);
				long long int rpvt = popcount(r);
				for (long long int x = l; x <= r; x++) {
					if ((x ^ l) < (x ^ r)) {
						if (popcount(x) == lpvt) {
							res[x - l] = '1';
						}
						else {
							res[x - l] = '0';
						}
					}
					else {
						if (popcount(x) == rpvt) {
							res[x - l] = '1';
						}
						else {
							res[x - l] = '0';
						}
					}
				}
			}
			else {
				long long int pvt = popcount(l);
				if (r % 2 == 0) {
					pvt = popcount(r);
				}
				pvt %= 2;
				for (long long int x = l; x <= r; x++) {
					if (popcount(x) == pvt) {
						res[x - l] = '1';
					}
					else {
						res[x - l] = '0';
					}
				}
			}
			res[r - l + 1] = 0;
			puts(res);
		}
	}
	return 0;
}

Submission Info

Submission Time
Task B - Hamming Distance is not 1
User gs12117
Language C++23 (GCC 15.2.0)
Score 800
Code Size 1617 Byte
Status AC
Exec Time 61 ms
Memory 13988 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 1
AC × 53
Set Name Test Cases
Sample sample.txt
All 1_1.txt, 1_10.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 1_6.txt, 1_7.txt, 1_8.txt, 1_9.txt, 2_1.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_2.txt, 2_3.txt, 2_4.txt, 2_5.txt, 2_6.txt, 2_7.txt, 2_8.txt, 2_9.txt, 3_1.txt, 3_10.txt, 3_11.txt, 3_12.txt, 3_13.txt, 3_14.txt, 3_15.txt, 3_16.txt, 3_17.txt, 3_18.txt, 3_19.txt, 3_2.txt, 3_20.txt, 3_21.txt, 3_22.txt, 3_23.txt, 3_24.txt, 3_25.txt, 3_26.txt, 3_27.txt, 3_28.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 3_7.txt, 3_8.txt, 3_9.txt, sample.txt
Case Name Status Exec Time Memory
1_1.txt AC 59 ms 11564 KiB
1_10.txt AC 56 ms 12508 KiB
1_2.txt AC 61 ms 13332 KiB
1_3.txt AC 57 ms 12036 KiB
1_4.txt AC 57 ms 11732 KiB
1_5.txt AC 59 ms 11236 KiB
1_6.txt AC 58 ms 11748 KiB
1_7.txt AC 54 ms 10404 KiB
1_8.txt AC 56 ms 12760 KiB
1_9.txt AC 56 ms 13988 KiB
2_1.txt AC 2 ms 1532 KiB
2_10.txt AC 7 ms 10360 KiB
2_11.txt AC 9 ms 10324 KiB
2_12.txt AC 7 ms 10180 KiB
2_13.txt AC 7 ms 10312 KiB
2_14.txt AC 3 ms 3072 KiB
2_2.txt AC 7 ms 10356 KiB
2_3.txt AC 7 ms 10204 KiB
2_4.txt AC 7 ms 10236 KiB
2_5.txt AC 7 ms 10236 KiB
2_6.txt AC 7 ms 10356 KiB
2_7.txt AC 7 ms 10196 KiB
2_8.txt AC 7 ms 10140 KiB
2_9.txt AC 7 ms 10356 KiB
3_1.txt AC 46 ms 2964 KiB
3_10.txt AC 7 ms 8584 KiB
3_11.txt AC 7 ms 8696 KiB
3_12.txt AC 5 ms 6732 KiB
3_13.txt AC 5 ms 6608 KiB
3_14.txt AC 5 ms 6688 KiB
3_15.txt AC 6 ms 6516 KiB
3_16.txt AC 5 ms 6672 KiB
3_17.txt AC 5 ms 5704 KiB
3_18.txt AC 5 ms 5692 KiB
3_19.txt AC 6 ms 5472 KiB
3_2.txt AC 28 ms 8996 KiB
3_20.txt AC 5 ms 5704 KiB
3_21.txt AC 5 ms 5648 KiB
3_22.txt AC 5 ms 5544 KiB
3_23.txt AC 5 ms 6144 KiB
3_24.txt AC 5 ms 5700 KiB
3_25.txt AC 6 ms 5960 KiB
3_26.txt AC 6 ms 5676 KiB
3_27.txt AC 6 ms 5560 KiB
3_28.txt AC 6 ms 3404 KiB
3_3.txt AC 6 ms 8556 KiB
3_4.txt AC 6 ms 8620 KiB
3_5.txt AC 6 ms 8660 KiB
3_6.txt AC 6 ms 8760 KiB
3_7.txt AC 6 ms 8668 KiB
3_8.txt AC 6 ms 8612 KiB
3_9.txt AC 6 ms 8692 KiB
sample.txt AC 1 ms 1616 KiB