QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#316625#8177. Sum is Integerucup-team2112#WA 70ms18660kbC++202.9kb2024-01-27 23:24:432024-01-27 23:24:44

Judging History

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

  • [2024-01-27 23:24:44]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:18660kb
  • [2024-01-27 23:24:43]
  • 提交

answer

#include <bits/stdc++.h>

const int maxn = 1e5 + 1;
const int base1 = 13331;
const int mod1 = 1e9 + 7;
const int base2 = 233;
const int mod2 = 1e9 + 9;
using pii = std::pair<int, int>;

pii operator +(const pii &a, const pii &b) {
    return {(a.first + b.first) % mod1, (a.second + b.second) % mod2};
}

pii operator -(const pii &a, const pii &b) {
    return {(a.first - b.first + mod1) % mod1, (a.second - b.second + mod2) % mod2};
}

pii operator *(const pii &a, const pii &b) {
    return {(1LL * a.first * b.first) % mod1, (1LL * a.second * b.second) % mod2};
}

void solve(){
    int n;
    std::cin >> n;
    std::vector<std::priority_queue<int> > pq(maxn);
    std::vector<int> cnt(maxn);
    std::vector factor(maxn, std::vector<int>());
    std::vector<pii> pw(maxn);
    pw[0] = {1, 1};
    for (int i = 1; i < maxn; i += 1) {
        pw[i] = pw[i - 1] * pii(base1, base2);
    }
    pii h = {0, 0};
    for (int i = 1; i < maxn; i += 1) {
        for (int j = i + i; j < maxn; j += i) {
            factor[j].push_back(i);
        }
    }
    auto add = [&](int x, int c) {
        h = h - pw[x] * pii(cnt[x], cnt[x]);
        cnt[x] = (cnt[x] + x + c % x) % x;
        h = h + pw[x] * pii(cnt[x], cnt[x]);
    };

    std::map<pii, int> mp;
    mp[h] = 1;
    long long res = 0;
    for (int i = 1; i <= n; i += 1) {
        int x, c;
        std::cin >> c >> x;
        int last = x;
        bool nice = false;
        while(true) {
            if (pq[last].empty()) {
                break;
            }
            int y = pq[last].top();
            if (cnt[y] == 0) {
                pq[last].pop();
                continue;
            }
            add(y, c * (y / x));
            last = y;
            nice = true;
            break;
        }
        if (not nice) {
            add(last, c);
        }
        else {
            while(true) {
                if (cnt[last] == 0) {
                    break;
                }
                int g = std::gcd(last, cnt[last]);
                if (g == 1) {
                    break;
                }
                add(last / g, cnt[last] / g);
                add(last, -cnt[last]);
                last /= g;
            }
        }
        if (cnt[last]) {
            for (auto g : factor[last]) {
                pq[g].push(last);
            }
        }
        res += mp[h];
        mp[h] += 1;
        // std::cout << i << "\n";
        // for (int j = 1; j <= 20; j += 1) {
        //     if (cnt[j]) {
        //         std::cout << "(" << j << ", " << cnt[j] << ") ";
        //     }
        // }
        // std::cout << "\n";
        // std::cout << h.first << " " << h.second << "\n";
    }
    std::cout << res << "\n";
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 17816kb

input:

4
1 6
1 3
1 2
1 2

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 28ms
memory: 17800kb

input:

5
1 1
2 2
3 3
4 4
5 5

output:

15

result:

ok "15"

Test #3:

score: 0
Accepted
time: 38ms
memory: 17880kb

input:

2
1 99999
99999 100000

output:

0

result:

ok "0"

Test #4:

score: 0
Accepted
time: 55ms
memory: 17920kb

input:

200000
82781 82781
86223 86223
16528 16528
84056 84056
94249 94249
54553 54553
25943 25943
10415 10415
52417 52417
46641 46641
70298 70298
84228 84228
55441 55441
49326 49326
11753 11753
89499 89499
58220 58220
71482 71482
32373 32373
7251 7251
78573 78573
74268 74268
46682 46682
20314 20314
85519 8...

output:

10603308211

result:

ok "10603308211"

Test #5:

score: -100
Wrong Answer
time: 70ms
memory: 18660kb

input:

200000
50741 50741
86798 95775
51104 51104
29372 29372
43295 43295
55065 55065
68947 68947
35282 35282
62467 62467
68481 68481
82613 82613
95921 95921
46302 46302
53806 53806
61244 61244
16078 16078
33476 33476
9084 9084
99273 99273
11678 11678
36816 36816
30311 30311
51479 51479
2667 2667
57043 570...

output:

15218308

result:

wrong answer 1st words differ - expected: '20066919', found: '15218308'