QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322942 | #8177. Sum is Integer | ucup-team134# | WA | 126ms | 5672kb | C++14 | 2.3kb | 2024-02-08 00:56:45 | 2024-02-08 00:56:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
int mod;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=2e5+10;
/*const int nmods=2;/// must be even
int mods[nmods]={998244353,(int)1e9+7,(int)1e9+9,993192119,1000000861,1000001053};*/
const int nmods=2;/// must be even
int mods[nmods]={998244353,(int)1e9+7};
struct pt{
int a[nmods];
pt(){memset(a,0,sizeof(a));}
pt(int p,int q){
for(int i=0;i<nmods;i++){
mod=mods[i];
a[i]=mul(p,invv(q));
}
}
pt operator +(pt b){
pt ret;
for(int i=0;i<nmods;i++){
mod=mods[i];
ret.a[i]=add(a[i],b.a[i]);
}
return ret;
}
pt operator -(pt b){
pt ret;
for(int i=0;i<nmods;i++){
mod=mods[i];
ret.a[i]=sub(a[i],b.a[i]);
}
return ret;
}
ll get_diagonal(){
ll ret=0;
for(int i=0;i<nmods;i++){
if(i%2==0)ret+=a[i];
else ret-=a[i];
}
return ret;
}
}niz[maxn];
void ubaci(pt p,map<ll,ll>&mapa){
for(int i=0;i<(1<<nmods);i++){
pt np=p;
for(int j=0;j<nmods;j++){
if(i&(1<<j)){}
else np.a[j]-=mods[j];
}
/// printf("%lld added\n",diag);
mapa[np.get_diagonal()]++;
}
}
int main(){
///freopen("test.txt","r",stdin);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int p,q;
scanf("%d %d",&p,&q);
niz[i]=pt(p,q);
niz[i]=niz[i-1]+niz[i];
}
map<ll,ll>mapa;
ubaci(niz[0],mapa);
ll rez=0;
for(int i=1;i<=n;i++){
///printf("%lld DIAG %lld\n",niz[i].get_diagonal(),mapa[niz[i].get_diagonal()]);
rez+=mapa[niz[i].get_diagonal()];
ubaci(niz[i],mapa);
}
printf("%lld\n",rez);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5332kb
input:
4 1 6 1 3 1 2 1 2
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5440kb
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: 5672kb
input:
2 1 99999 99999 100000
output:
0
result:
ok "0"
Test #4:
score: -100
Wrong Answer
time: 126ms
memory: 5552kb
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'