QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#316768 | #8177. Sum is Integer | ucup-team2894# | WA | 126ms | 16736kb | C++20 | 1.6kb | 2024-01-28 03:29:43 | 2024-01-28 03:29:44 |
Judging History
answer
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(a) (a).begin(), (a).end()
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
using namespace std;
#ifdef ONPC
mt19937 rnd(223);
#else
mt19937 rnd(chrono::high_resolution_clock::now()
.time_since_epoch().count());
#endif
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using lll = __int128;
using ld = long double;
const int maxn = 1e6 + 100, inf = 1e9 + 100;
const lll mod = lll(1e9+7)*lll(1e9+9);
const lll pmod = lll(1e9+6)*lll(1e9+8);
lll po(lll a,lll b) {
lll ans = 1;
for(a%=mod;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;
return ans;
}
lll inv(lll x) {
return po(x,pmod-1);
}
ll p[maxn], q[maxn];
lll msum[maxn];
void solve() {
int n;
cin >> n;
ld dsum = 0;
map<lll,ll> ct;
for(int i=1;i<=n;i++) {
// cerr << i << endl;
cin >> p[i] >> q[i];
lll mv = p[i]*inv(q[i])%mod;
dsum += ld(p[i])/q[i];
lll adj = roundl(dsum);
mv-=adj;
dsum-=adj;
msum[i]=(msum[i-1]+mv)%mod;
if(msum[i]<0)msum[i]+=mod;
ct[msum[i]]++;
// cerr << ll(msum[i]) << endl;
}
ct[0]++;
ll ans = 0;
for(auto [v,x] : ct) {
// cerr << ll(v) << " " << x << endl;
ans += x*(x-1+(ct.count((v+mod-1)%mod)?ct[(v+mod-1)%mod]:0)+(ct.count(v+1%mod)?ct[(v+1)%mod]:0));
}
cout << ans /2 << "\n";
}
int main() {
#ifdef ONPC
freopen("../a.in", "r", stdin);
// freopen("../a.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(20);
solve();
cerr << "\n\nConsumed " << TIME << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8000kb
input:
4 1 6 1 3 1 2 1 2
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8108kb
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: 8016kb
input:
2 1 99999 99999 100000
output:
0
result:
ok "0"
Test #4:
score: -100
Wrong Answer
time: 126ms
memory: 16736kb
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'