QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#708867#6510. Best Carry Player 3orz_zWA 30ms3624kbC++144.4kb2024-11-04 09:00:222024-11-04 09:00:23

Judging History

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

  • [2024-11-04 09:00:23]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:3624kb
  • [2024-11-04 09:00:22]
  • 提交

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();
	F(t, 1, 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;
		}
		if(t == 5342) {
			cout << X << ' ' << Y << ' ' << K << " @@\n";
			return 0;
		}
		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);
		}
		if(T != 100000) 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: 30ms
memory: 3600kb

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:

59
137
121
388
36
108
15
59
78
17
191
11
335
88
156
74
176
70
247
297
56
210
177
58
13
296
208
392
53
49
279
363
3
314
248
246
278
274
83
75
359
410
4
26
180
464
115
388
80
269
22
3
114
251
378
19
457
69
360
406
189
38
155
10
412
460
297
13
197
465
102
170
251
315
202
444
322
233
352
446
333
102
184...

result:

wrong answer 1st numbers differ - expected: '87', found: '59'