QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743565 | #9597. Grade 2 | lonelywolf# | WA | 2344ms | 238844kb | C++17 | 2.6kb | 2024-11-13 19:30:39 | 2024-11-13 19:30:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
constexpr uint mod = (1ull << 61) - 1;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<uint> dist(mod / 2, mod - 1);
const uint base = dist(rnd);
static inline uint add(uint a, uint b) {
a += b;
if (a >= mod) {
a -= mod;
}
return a;
}
static inline uint mul(uint a, uint b) {
__uint128_t c = __uint128_t(a) * b;
return add(c >> 61, c & mod);
}
vector<int> power;
void init(int n) {
power.resize(n);
power[0] = 1;
for (int i = 1; i < n; i++) {
power[i] = mul(power[i - 1], base);
}
}
vector<uint> build(const vector<int> &s) {
int n = s.size() - 1;
vector<uint> hashed(n + 1);
for (int i = 1; i <= n; i++) {
hashed[i] = add(mul(hashed[i - 1], base), s[i]);
}
return hashed;
}
uint query(const vector<uint> &s, int l, int r) {
return add(s[r], mod - mul(s[l - 1], power[r - l + 1]));
}
uint merge(uint h1, uint h2, int len2) {
return add(mul(h1, power[len2]), h2);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, n;
cin >> x >> n;
if (x % 2 == 0) {
while (n--) {
int l, r;
cin >> l >> r;
cout << 0 << "\n";
}
return 0;
}
if (x == 1) {
while (n--) {
int l, r;
cin >> l >> r;
cout << r - l + 1 << "\n";
}
return 0;
}
vector<int> t;
int f = 1;
int b = 0;
int lst = 0;
while (t.size() < (int)1e7) {
if (gcd((f * x) ^ x, x) == 1) {
if (b == 0) {
b = f;
} else {
t.push_back(f - lst);
}
lst = f;
}
f++;
}
init(1e7 + 10);
auto hash = build(t);
int len = 0;
for (int i = 5000000; i >= 2; i -= 2) {
if (query(hash, 1, i) == query(hash, i + 1, 2 * i)) {
len = i;
break;
}
}
for (int i = 1; i < len; i++) {
t[i] += t[i - 1];
}
int T = t[len - 1];
auto calc = [&](int a) {
if (a < b) {
return 0LL;
}
a -= b;
int ret = 1 + a / T * t.size();
a %= T;
int l = -1, r = len;
while (l + 1 != r) {
int m = (l + r) / 2;
if (t[m] <= a) {
l = m;
} else {
r = m;
}
}
ret += l + 1;
return ret;
};
while (n--) {
int l, r;
cin >> l >> r;
cout << calc(r) - calc(l - 1) << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 639ms
memory: 238844kb
input:
15 2 1 4 11 4514
output:
2 2252
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 18ms
memory: 3536kb
input:
500696 100000 110442401300 646889080214 337192 670162015551 508011001649 508011014425 94418501628 94418501634 824168677375 824168677376 732815842309 795402573302 353241304050 846773277757 622033633276 622033633284 760381702139 760381702143 207714 795408271057 382792 952061527685 686173 331215904334 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 18ms
memory: 3612kb
input:
465262 100000 119442423888 249533375982 528365238401 528365275157 654839906300 654839906303 135820863700 135820967840 336231 918143221477 568175915485 568176067832 993015103483 993015103488 951474 444595379179 298623434750 298623434751 257961 410491919396 996297715292 996297994388 17765498878 177654...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 14ms
memory: 3560kb
input:
599394 100000 683408 868635908987 347999512025 347999739145 740945 377178907084 399211757563 399211757568 766968 548821086083 630762 702128377806 756554924031 756554924036 904713771313 904714518208 17026878789 17027129255 11601638470 206412869961 253365321722 253365321730 785476956554 785477402085 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #5:
score: -100
Wrong Answer
time: 2344ms
memory: 238548kb
input:
255255 100000 693776785134 693776920782 174578728959 174578728960 109045569231 631173362385 470661333171 470661439492 401883 183360880923 436203696728 436203931780 165055 339075075373 640081 299360395352 864237441330 864237509663 730335563579 730335652091 194265481215 194265481219 40664920117 406649...
output:
48406 1 375801818714 37959 131972216162 83815 244050292755 215462694780 24327 31556 2 13697 28081 525412348026 106032034810 4 93233979715 3 354071193746 2 47909 521274855839 661159768681 2 22468 54932 93652679333 92210958963 190928227363 55243 2 307440794478 2 221534549405 184214366229 292570937200 ...
result:
wrong answer 3rd lines differ - expected: '186110004314', found: '375801818714'