QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#231762#858. GCD vs. XORTibrellaAC ✓8639ms99032kbC++141.5kb2023-10-29 16:13:572023-10-29 16:13:58

Judging History

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

  • [2023-10-29 16:13:58]
  • 评测
  • 测评结果:AC
  • 用时:8639ms
  • 内存:99032kb
  • [2023-10-29 16:13:57]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;

using i32 = int;
using i64 = long long;

static i32 gcd(i32 a, i32 b) {
    while (b) {
        a = a % b;
        std::swap(a, b);
    }
    return a;
}

#define V 2000001
#define N 2000001

std::vector<i32> ans[V];

i32 f[N], t[V];

void solve(const i32& tim) {
    i32 n;
    i64 res = 0;
    cin >> n;
    for (i32 i = 1; i <= n; ++ i) {
        i32 x;
        cin >> x;
        if (t[x] != tim) t[x] = tim, f[x] = 0;
        else res += f[x];
        for (const auto& v : ans[x]) {
            // cout<< v << ' ';
            if (v >= V) break;
            if (t[v] != tim) t[v] = tim, f[v] = 0;
            ++f[v];
        }
        // cout<< '\n';
    }
    cout << res << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    for (i32 i = 2; i <= 1000000; ++ i) {
        ans[i].emplace_back(i ^ 1);
        for (i32 j = 2, lim = sqrt(i); j <= lim; ++ j) {
            if (i % j == 0) {
                if ((i ^ j) < V && gcd(i ^ j, i) == j) ans[i ^ j].emplace_back(i);
                if (i / j != j && (i ^ (i/j)) < V && gcd(i ^ (i/j), i) == (i/j)) 
                    ans[i ^ (i/j)].emplace_back(i); 
            }
        }
    }

    // for (i32 i = 1; i <= 10; ++ i) {
    //     for (const auto& x : ans[i]) cout << x << ' ';
    //     cout << '\n';
    // }

    i32 t;
    cin >> t;
    while (t--) solve(t);

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1701ms
memory: 90224kb

input:

1
4
2 3 4 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1691ms
memory: 91168kb

input:

20
43
128 66 452 384 400 441 232 203 228 33 284 156 128 190 197 292 388 31 179 343 147 206 450 284 180 73 273 130 168 250 405 203 235 340 309 28 267 395 152 191 295 463 344
54
48 7 12 37 49 24 5 18 15 37 26 57 53 59 22 10 2 16 36 52 64 1 56 42 38 46 53 7 2 8 60 38 54 11 19 50 20 61 6 50 27 5 26 3 4 ...

output:

9
54
13
7
8
34
47
11
1
102
6
5
37
1
3
8
8
348
15
0

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 8639ms
memory: 99032kb

input:

20
1318434
383714 853663 66866 511925 858736 184314 296349 849141 468962 414270 917939 220934 778184 984811 194692 105206 528188 310859 57152 790101 274637 529663 931099 79533 179471 539390 210762 400829 514992 127623 369248 168711 380204 767781 753089 645551 714964 101060 340524 937457 928656 65201...

output:

3032046
3638995
2800796
2440602
4854508
3744477
2051988
2014444
1784404
4514141
3348718
2455324
2051403
2133141
3042193
4827212
4227070
2349812
6977138
999999972775

result:

ok 20 numbers