QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848941 | #9878. A xor B plus C | hos_lyric | AC ✓ | 2426ms | 103484kb | C++14 | 6.4kb | 2025-01-09 10:53:47 | 2025-01-09 10:53:50 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
void exper(int A, int B, int C) {
constexpr int E = 20;
constexpr int N = 160;
vector<unsigned> X(N);
X[0] = A;
X[1] = B;
for (int i = 2; i < N; ++i) X[i] = (X[i - 1] ^ X[i - 2]) + C;
for (int e = 0; e < E; ++e) {
for (int i = 0; i < N; ++i) printf("%u", X[i] >> e & 1);
puts("");
}
puts("");
for (int e = 0; e < E; ++e) {
const int mask = (1 << e) - 1;
for (int i = 2; i < N; ++i) printf("%u", (((X[i - 1] ^ X[i - 2]) & mask) + (C & mask)) >> e & 1);
puts("");
}
puts("");
}
/*
x[e][i]: e-th bit
y[e][i]: carry to x[e][i+2]
x[e][0] = A[e]
x[e][1] = B[e]
x[e][i+2] + 2 y[e+1][i] = (x[e][i] XOR x[e][i+1]) + C[e] + y[e][i]
over F_2
x[e](q) = A[e] + B[e] q + (q+q^2) x[e](q) + C[e] q^2/(1+q) + y[e](q) q^2
x[e](q) = A[e] 1/(1+q+q^2) + B[e] q/(1+q+q^2) + C[e] q^2/(1+q^3) + y[e](q) q^2/(1+q+q^2)
y[e+1][i] = C[e] (x[e][i] XOR x[e][i+1]) + C[e] y[e][i] + (x[e][i] + x[e][i+1]) y[e][i]
y[e] -> y[e+1]: divide by (1+q+q^2), pointwise product
basis: \alpha^i binom(i,k) (\alpha in F_4, 0 <= k < 2^e)
denominator 1/(1+q^3)^(2^e)
x[e], y[e] have period 3 2^(e-1)
after A[e] = B[e] = C[e] = 0
x[e](q) = y[e](q) q^2/(1+q+q^2)
q^2/(1+q+q^2) = 001(101)*
y[e+1][i] = (x[e][i] + x[e][i+1]) y[e][i]
*/
// constexpr int E = 11;
constexpr int E = 21;
int main() {
// exper(1, 2, 3);
// exper(123, 456, 789);
int A, B, C;
Int N;
for (; ~scanf("%d%d%d%lld", &A, &B, &C, &N); ) {
--N;
const int mask = (1 << E) - 1;
vector<int> xs((3 << E) + 2);
xs[0] = A;
xs[1] = B;
for (int i = 0; i < 3 << E; ++i) xs[i + 2] = ((xs[i] ^ xs[i + 1]) + C) & mask;
Mint ans = xs[N % (3 << E)];
// { y[e][i] = 1 | 0 <= i < 3 2^e && 0 <= i < N }
vector<Int> is;
for (int i = 0; i < 3 << E && i < N; ++i) if (((xs[i] ^ xs[i + 1]) + C) >> E) is.push_back(i);
Int per = 3 << E;
Mint two = 1 << E;
for (; is.size(); ) {
// cerr<<"per = "<<per<<", is = "<<is<<endl;
int x = 0;
for (const Int i : is) {
if ((N - i) % 3 != 1) {
x ^= ((N - i - 1) / per + 1) & 1;
}
}
ans += two * x;
vector<Int> iis;
int now[3] = {};
for (int h = 0; h < 2; ++h) {
for (const Int i : is) if (h * per + i < N) {
if (now[i % 3] ^ now[(i + 1) % 3]) iis.push_back(h * per + i);
now[i % 3] ^= 1;
now[(i + 2) % 3] ^= 1;
}
}
chmin(per *= 2, N + 1);
two *= 2;
is.swap(iis);
}
printf("%u\n", ans.x);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 27728kb
input:
1 2 3 4
output:
7
result:
ok "7"
Test #2:
score: 0
Accepted
time: 12ms
memory: 28012kb
input:
123 456 789 123456789
output:
567982455
result:
ok "567982455"
Test #3:
score: 0
Accepted
time: 10ms
memory: 27852kb
input:
0 0 0 1000000000000000000
output:
0
result:
ok "0"
Test #4:
score: 0
Accepted
time: 7ms
memory: 27972kb
input:
628 314 157 1
output:
628
result:
ok "628"
Test #5:
score: 0
Accepted
time: 11ms
memory: 27684kb
input:
167 924 167 2
output:
924
result:
ok "924"
Test #6:
score: 0
Accepted
time: 13ms
memory: 27700kb
input:
1048575 1048575 1048575 1000000000000000000
output:
1048575
result:
ok "1048575"
Test #7:
score: 0
Accepted
time: 2340ms
memory: 102944kb
input:
287144 758614 992207 1000000000000000000
output:
638555367
result:
ok "638555367"
Test #8:
score: 0
Accepted
time: 2233ms
memory: 101960kb
input:
442510 534717 936857 1000000000000000000
output:
125005501
result:
ok "125005501"
Test #9:
score: 0
Accepted
time: 2364ms
memory: 103260kb
input:
507590 985947 1025549 999999999999999833
output:
363289377
result:
ok "363289377"
Test #10:
score: 0
Accepted
time: 2426ms
memory: 102096kb
input:
989414 986755 1024915 1000000000000000000
output:
176552525
result:
ok "176552525"
Test #11:
score: 0
Accepted
time: 1942ms
memory: 97016kb
input:
773910 981383 748815 999999999999999372
output:
712048477
result:
ok "712048477"
Test #12:
score: 0
Accepted
time: 1348ms
memory: 71908kb
input:
539000 982202 549877 1000000000000000000
output:
49295427
result:
ok "49295427"
Test #13:
score: 0
Accepted
time: 1905ms
memory: 96972kb
input:
930318 901108 790115 999999999999999002
output:
446688556
result:
ok "446688556"
Test #14:
score: 0
Accepted
time: 2359ms
memory: 102388kb
input:
57298 210381 985237 1000000000000000000
output:
533555472
result:
ok "533555472"
Test #15:
score: 0
Accepted
time: 704ms
memory: 49776kb
input:
567956 1013479 284068 1000000000000000000
output:
13855344
result:
ok "13855344"
Test #16:
score: 0
Accepted
time: 2360ms
memory: 101052kb
input:
694266 795841 967344 1000000000000000000
output:
179712105
result:
ok "179712105"
Test #17:
score: 0
Accepted
time: 619ms
memory: 50356kb
input:
744515 402386 261828 1000000000000000000
output:
915814204
result:
ok "915814204"
Test #18:
score: 0
Accepted
time: 272ms
memory: 36888kb
input:
630928 108751 103226 1000000000000000000
output:
314920156
result:
ok "314920156"
Test #19:
score: 0
Accepted
time: 1390ms
memory: 75624kb
input:
408870 219543 576432 1000000000000000000
output:
332612604
result:
ok "332612604"
Test #20:
score: 0
Accepted
time: 2360ms
memory: 103484kb
input:
208613 769277 1010542 819875140559301752
output:
110220300
result:
ok "110220300"
Test #21:
score: 0
Accepted
time: 951ms
memory: 65860kb
input:
123844 719656 377241 520974001002628387
output:
986512272
result:
ok "986512272"
Test #22:
score: 0
Accepted
time: 2020ms
memory: 99320kb
input:
774205 820111 841396 711066335916901718
output:
254873758
result:
ok "254873758"
Test #23:
score: 0
Accepted
time: 2414ms
memory: 101512kb
input:
604531 395365 966071 999594448264125858
output:
505142123
result:
ok "505142123"
Test #24:
score: 0
Accepted
time: 2213ms
memory: 101624kb
input:
59523 598376 922420 752304351201620672
output:
351022203
result:
ok "351022203"
Test #25:
score: 0
Accepted
time: 2211ms
memory: 103480kb
input:
192450 176925 1037973 192583019203393748
output:
56600397
result:
ok "56600397"
Test #26:
score: 0
Accepted
time: 2224ms
memory: 103240kb
input:
972801 523798 994144 594688603126478507
output:
750534499
result:
ok "750534499"
Test #27:
score: 0
Accepted
time: 12ms
memory: 28164kb
input:
669131 939565 629 543390474884493567
output:
652889135
result:
ok "652889135"
Test #28:
score: 0
Accepted
time: 954ms
memory: 62960kb
input:
829091 688584 371532 935387048229453232
output:
784327643
result:
ok "784327643"
Test #29:
score: 0
Accepted
time: 366ms
memory: 38960kb
input:
407113 311573 150840 428344291461283594
output:
486756568
result:
ok "486756568"
Test #30:
score: 0
Accepted
time: 671ms
memory: 50868kb
input:
338931 949581 280744 289664704872449795
output:
459928211
result:
ok "459928211"
Test #31:
score: 0
Accepted
time: 1006ms
memory: 68160kb
input:
16277 434162 426083 575309380820099707
output:
927534514
result:
ok "927534514"
Test #32:
score: 0
Accepted
time: 1315ms
memory: 72632kb
input:
669467 627218 559817 371026815047584891
output:
393999810
result:
ok "393999810"
Test #33:
score: 0
Accepted
time: 614ms
memory: 50700kb
input:
256940 648067 248598 702551234623621497
output:
107167397
result:
ok "107167397"
Test #34:
score: 0
Accepted
time: 207ms
memory: 45292kb
input:
112359 956967 160416 704822623170226832
output:
945781095
result:
ok "945781095"
Test #35:
score: 0
Accepted
time: 2222ms
memory: 100752kb
input:
608294 272679 879126 922348606336628938
output:
508826865
result:
ok "508826865"
Test #36:
score: 0
Accepted
time: 958ms
memory: 66088kb
input:
844223 856121 402112 640219260480538711
output:
494733011
result:
ok "494733011"
Test #37:
score: 0
Accepted
time: 215ms
memory: 33964kb
input:
589375 991964 85955 471255438930064341
output:
591777452
result:
ok "591777452"
Test #38:
score: 0
Accepted
time: 1225ms
memory: 73108kb
input:
613807 685977 493404 774205724944088968
output:
686401274
result:
ok "686401274"
Test #39:
score: 0
Accepted
time: 133ms
memory: 32448kb
input:
686801 458561 52258 593361261434725536
output:
197205169
result:
ok "197205169"
Extra Test:
score: 0
Extra Test Passed