hdu 4812 树分治+逆元+手写hashmap
a*b%mod==k等价于k*inv(b)%mod==a 然后树分治,用hashmap记录即可,unorder_map/map貌似会TLE,我手写了一个 注意这个小范围的逆元可以直接线性处理 复杂度$nlogn*hashmap$ #include<bits/stdc++.h> #define ll long long #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define fi first #define se second #define mp make_pair #define pii pair<ll,ll> using namespace std; const int maxn=1e6+10,maxm=2e6+10; const ll INF=0x88888888,mod=1e6+3; int casn,n,m,k; ll val[maxn],inv[maxn]; const int maxsz=4e6+9;//@素数表@:1e7+19,2e7+3,3e7+23 //1e6+3,2e6+3,3e6+7,4e6+9,1e5+3,2e5+3,3e5+7,4e5+9 //@要保证取值的操作次数小于maxsz