QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325475 | #8177. Sum is Integer | BUET_POTATOES# | WA | 145ms | 16248kb | C++20 | 1.5kb | 2024-02-11 14:33:55 | 2024-02-11 14:33:56 |
Judging History
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 = 998244353;
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;
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3772kb
input:
4 1 6 1 3 1 2 1 2
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
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: 3560kb
input:
2 1 99999 99999 100000
output:
0
result:
ok "0"
Test #4:
score: -100
Wrong Answer
time: 145ms
memory: 16248kb
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'