QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708869 | #6510. Best Carry Player 3 | orz_z | WA | 30ms | 3700kb | C++14 | 4.5kb | 2024-11-04 09:01:44 | 2024-11-04 09:01:44 |
Judging History
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) {
if(T != 100000) puts("0");
continue;
}
if(!K) {
if(T != 100000) 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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
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: 3604kb
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:
50 53 5 @@
result:
wrong answer 1st numbers differ - expected: '87', found: '50'