QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#708866#6510. Best Carry Player 3orz_zWA 557ms3624kbC++144.3kb2024-11-04 08:59:122024-11-04 08:59:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 08:59:13]
  • 评测
  • 测评结果:WA
  • 用时:557ms
  • 内存:3624kb
  • [2024-11-04 08:59:12]
  • 提交

answer

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
	cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
	else if (s[i] == ')' || s[i] == '}') b--;
	else if (s[i] == ',' && b == 0) {
		cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
		debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
		break;
	}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;

int X, Y, K;

int get2(int x, int k) { // x 疑惑 (t <= k) 最小值
	bool lim = 1;
	dF(i, 59, 0) {
		int lt = (lim ? (k >> i & 1) : 1);
		int w = 0;
		if(x > (x ^ (lt << i)))  {
			x ^= (lt << i);
			w = 1;
		}
		if(lim && w < lt) lim = 0;
	}
	return x;
}

int get(int x) { // x 异或 (t<=k) 最大的<=y 的数
	bool lim = 1, lim2 = 1;
	int st = 0;
//	Debug("gt", x);
	dF(i, 59, 0) {
		int lt = (lim2 ? ((K >> i) & 1) : 1);
		int ly = (lim ? ((Y >> i) & 1) : 1);
		int w = 0;
		if(lim && lt && (x >> i) % 2 == 0 && ly) {
			if(!lim2) w = 1;
			else if(get2(x + (1ll << i), K - st - (1ll << i)) <= Y) {
				w = 1;
			}
		} else if(x < (x ^ (lt << i)) && (x ^ (lt << i)) <= Y) {
			w = 1;
		}
		x ^= (w << i);
		st ^= (w << i);
//		if(i <= 3) Debug(i, w, x);
		if(lim) {
			if((x >> i & 1) < (Y >> i & 1)) lim = 0;
		}
		if(lim2 && w < lt) lim2 = 0;
	}
	return x;
}

bool Med;
signed main() {
	// Mry;
	int T = ri();
	while(T--) {
		X = ri(), Y = ri(), K = ri();
		if(X > Y) swap(X, Y);
		if(X == Y) {
			puts("0");
			continue;
		}
		if(!K) {
			cout << Y - X << '\n';
			continue;
		}
		int ans = 0, w;
		int zkw = 0, zw2 = 0;
		while(X < Y) {
			int lst = X, fei = ans;
			while((w = get(X)) > X) {
				ans++;
				X = w;
//				Debug("xor", X);
			}
			if(X < Y) X++, ans++;
//			Debug("ad", X);
//			Debug(X,X- lst);
			zkw = X - lst, zw2 = ans - fei;
			if(ans >= 50) break;
		}
		ans += (Y - X) / zkw * zw2;
		X += zkw * ((Y - X) / zkw);
		while(X < Y) {
			while((w = get(X)) > X) {
				ans++;
				X = w;
//				Debug("xor", X);
			}
			if(X < Y) X++, ans++;
//			Debug("ad", X);
//			Debug(X,X- lst);
		}
		cout << ans << '\n';
	}
	// Try;
	return 0;
}

/*
8
4 5 0
5 8 3
9 2 6
15 28 5
97 47 8
164 275 38
114514 1919 810
0 1152921504606846975 1
548395 65746482135 667493
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

8
4 5 0
5 8 3
9 2 6
15 28 5
97 47 8
164 275 38
114514 1919 810
0 1152921504606846975 1

output:

1
2
3
5
11
6
331
1152921504606846975

result:

ok 8 numbers

Test #2:

score: -100
Wrong Answer
time: 557ms
memory: 3548kb

input:

100000
84 318 6
54 226 7
92 33 0
39 54 5
76 79 7
247 110 0
211 90 0
4 430 3
230 17 1
491 93 5
196 117 7
137 29 2
76 490 6
422 43 7
277 26 4
159 43 1
67 37 5
17 2 5
113 176 7
85 473 0
68 217 7
275 8 7
124 34 1
30 66 0
80 149 3
103 149 6
84 354 1
27 342 7
94 114 1
69 125 1
72 48 7
361 8 7
285 82 1
74 ...

output:

87
45
59
6
1
137
121
213
213
150
21
81
156
95
95
116
12
6
16
388
39
67
90
36
35
17
270
79
20
56
6
89
203
108
26
15
157
98
111
389
174
123
59
289
78
17
21
36
275
191
17
102
60
93
100
11
6
79
44
63
91
60
22
109
11
3
10
67
11
85
207
47
39
83
156
189
107
27
81
247
81
335
33
144
11
50
54
347
233
175
30
7...

result:

wrong answer 5342nd numbers differ - expected: '2', found: '3'