QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771543 | #7583. Faraway | tarjen# | AC ✓ | 282ms | 3616kb | C++20 | 2.9kb | 2024-11-22 14:03:04 | 2024-11-22 14:03:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2>
ostream& operator << (ostream& out,pair<T1,T2> p) {
out<<"("<<p.first<<","<<p.second<<")";
return out;
}
template<typename T>
ostream& operator << (ostream& out,vector<T>v) {
out<<"[";
if(!v.empty()){
cout<<v[0];
for(int i=1;i<v.size();i++)cout<<","<<v[i];
}
out<<"]";
return out;
}
typedef long long ll;
ll mul(ll a,ll b,ll mod){//O(1)取模快速乘,不会爆long long
return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;
}
ll exgcd(ll a, ll b, ll& x, ll& y){
if(!b){
x = 1, y = 0;
return a;
}
ll d = exgcd(b,a%b,y,x);
y -= a/b*x;
return d;
}
pair<ll,ll> getv(ll n,vector<ll>&mo,vector<ll>&res){
ll a1,m1;
a1=res[0],m1=mo[0];
bool ok = 1;
for(ll i=1;i<n;i++){
ll a2,m2,k1,k2;
m2=mo[i],a2=res[i];
ll d = exgcd(m1,m2,k1,k2);
if((a2-a1)%d) ok = 0;
else{
k1=mul(k1,(a2-a1)/d,m2/d);//这个地方必须要用取模快速乘
a1=a1+k1*m1;
m1=abs(m1/d*m2);
}
}
if(ok)return {(a1%m1+m1)%m1,m1};
else return {-1,-1};
}
ll query(ll l,ll mod,ll k){
return l/mod+((l%mod)>=k);
}
ll query(ll l,ll r,ll mod,ll k){
ll res=query(r,mod,k);
if(l>0)res-=query(l-1,mod,k);
return res;
}
struct kkk{
ll x,y,mod,t;
};
ll solve()
{
int n;cin>>n;
ll m;cin>>m;
vector<ll> X{0,m+1},Y{0,m+1};
vector<kkk> a(n);
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y>>a[i].mod>>a[i].t;
X.push_back(a[i].x);
Y.push_back(a[i].y);
}
sort(X.begin(),X.end());X.resize(unique(X.begin(),X.end())-X.begin());
sort(Y.begin(),Y.end());Y.resize(unique(Y.begin(),Y.end())-Y.begin());
ll ans=0;
for(int xx=0;xx+1<X.size();xx++){
ll lx=X[xx],rx=X[xx+1]-1;
for(int yy=0;yy+1<Y.size();yy++){
ll ly=Y[yy],ry=Y[yy+1]-1;
map<pair<ll,ll>,vector<ll>> mo;
map<pair<ll,ll>,vector<ll>> res;
for(int x=0;x<60;x++){
for(int y=0;y<60;y++){
int flag=0;
for(int i=0;i<n;i++){
// opx*X+opy*Y+k %mod =t
ll opx=1,opy=1,k=0;
if(lx>=a[i].x)opx=1,k+=-a[i].x;
else opx=-1,k+=a[i].x;
if(ly>=a[i].y)opy=1,k+=-a[i].y;
else opy=-1,k+=a[i].y;
ll Mod=a[i].mod;
if(((x*opx+y*opy+k)%Mod+Mod)%Mod==a[i].t){
flag++;
}
}
if(flag==n)ans+=query(lx,rx,60,x)*query(ly,ry,60,y);
}
}
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;while(T--)cout<<solve()<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
2 2 5 1 2 4 2 3 1 2 1 2 5 1 2 4 2 1 2 4 3
output:
10 0
result:
ok 2 number(s): "10 0"
Test #2:
score: 0
Accepted
time: 282ms
memory: 3552kb
input:
10 10 950006 879210 618398 2 0 413993 805537 5 0 614389 782151 5 4 616385 454674 4 2 6020 332147 5 0 77932 43110 4 1 143614 196643 4 0 937161 934707 4 1 318567 789911 4 0 194658 555381 5 3 10 967857178 8983267 44864625 3 2 141087113 359274718 2 1 909006720 262061158 3 0 840340929 715591525 3 2 76531...
output:
0 0 0 116256265 43298776834 1839945977784 820599567890959 19922821864719464 50544306663055 64150016306836
result:
ok 10 numbers