QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325469#8177. Sum is IntegerBUET_POTATOES#WA 155ms16172kbC++201.5kb2024-02-11 14:23:292024-02-11 14:23:30

Judging History

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

  • [2024-02-11 14:23:30]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:16172kb
  • [2024-02-11 14:23:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using OST = tree<T,null_type,less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
//find_by_order(k):iterator to kth smallest(0 ind)
//order_of_key(x) :  no of items  < x

const ll M1 = 1e9+7;
const ll M2 = 1e9+9;

const ll M12 = M1 * M2;

template<ll M>
ll modexpo(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) ret = ret * x % M;
        x = x * x % M;
        n >>= 1;
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    int n;
    cin>>n;

    const ll M2inv = modexpo<M1>(M2, M1-2);
    const ll M1inv = modexpo<M2>(M1, M2-2);

    OST<pair<ll, int>> ost;
    ost.insert({0ll, -1});

    ll ans = 0;
    ll sum = 0;

    for(int i = 0; i<n; i++){
        ll p, q;
        cin>>p>>q;
        p %= q;

        ll x = p * modexpo<M1>(q, M1-2);
        ll y = p * modexpo<M2>(q, M2-2);

        ll h = (__int128(x) * M2 * M2inv  + __int128(y) * M1 * M1inv) % M12;
        sum = (sum + h) % M12;
//        cout<<i <<" - "<<sum<<endl;

        ans += ost.order_of_key({sum, n+1}) - ost.order_of_key({sum-n, -2}) ; // all (x,i) such that h-n <= x <= h

        ost.insert({sum, i});
    }

    cout<<ans<<endl;

    return 0;
}
/*
4
1 6
1 3
1 2
1 2


5
1 1
2 2
3 3
4 4
5 5


2
1 99999
99999 100000
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

input:

4
1 6
1 3
1 2
1 2

output:

2

result:

ok "2"

Test #2:

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

input:

5
1 1
2 2
3 3
4 4
5 5

output:

15

result:

ok "15"

Test #3:

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

input:

2
1 99999
99999 100000

output:

0

result:

ok "0"

Test #4:

score: -100
Wrong Answer
time: 155ms
memory: 16172kb

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'