QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355155#8177. Sum is Integerwillow#WA 81ms5572kbC++171.2kb2024-03-16 13:57:552024-03-16 13:57:55

Judging History

This is the latest submission verdict.

  • [2024-03-16 13:57:55]
  • Judged
  • Verdict: WA
  • Time: 81ms
  • Memory: 5572kb
  • [2024-03-16 13:57:55]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7, mod2 = 998244353;
int Add(int x, int y, int mod) {
    return (x += y) >= mod ? x - mod : x;
}
int Sub(int x, int y, int mod) {
    return (x -= y) < 0 ? x + mod : x;
}
int Mul(int x, int y, int mod) {
    return 1ll * x * y % mod;
}
int Pow(int x, int y, int mod) {
    int res = 1;
    for(; y; x = Mul(x, x, mod), y >>= 1)
        if(y & 1)
            res = Mul(res, x, mod);
    return res;
}
const int maxn = 2e5 + 5;
int n, a[maxn], b[maxn];
map<long long, int> cnt;
int main() {
    scanf("%d", &n);
    for(int i = 1, p, q; i <= n; ++ i) {
        scanf("%d%d", &p, &q);
        a[i] = Add(a[i - 1], Mul(p, Pow(q, mod1 - 2, mod1), mod1), mod1);
        b[i] = Add(b[i - 1], Mul(p, Pow(q, mod2 - 2, mod2), mod2), mod2);
    }
    long long ans = 0;
    for(int i = 0; i <= n; ++ i) {
        for(int j = 0; j < 4; ++ j) {
            long long diff = b[i] - a[i];
            if(j & 1)
                diff -= mod1;
            if(j & 2)
                diff += mod2;
            if(cnt.count(diff))
                ans += cnt[diff];
        }
        ++ cnt[b[i] - a[i]];
    }
    printf("%lld\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3912kb

input:

4
1 6
1 3
1 2
1 2

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

5
1 1
2 2
3 3
4 4
5 5

output:

15

result:

ok "15"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3920kb

input:

2
1 99999
99999 100000

output:

0

result:

ok "0"

Test #4:

score: -100
Wrong Answer
time: 81ms
memory: 5572kb

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:

19799405515

result:

wrong answer 1st words differ - expected: '10603308211', found: '19799405515'