QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#91493#5. 在线 O(1) 逆元Crysfly#Compile Error//C++173.1kb2023-03-28 22:58:182024-11-05 21:47:37

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 21:47:37]
  • 管理员手动重测本题所有提交记录
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-28 22:58:21]
  • 评测
  • [2023-03-28 22:58:18]
  • 提交

answer

#include "inv.h"
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;

#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi; 

#define maxn 300005
#define inf 0x3f3f3f3f

struct DIV {
	ull x;
	inline void init(int v) { x = -1ull / v + 1; }
};
inline ull operator / (const ull & x, const DIV & y) {
	return (__uint128_t) x * y.x >> 64;
}

namespace Inv{

int n=1000,m=1000000,sum[1000005],frac[1000005];
int f[maxn],len,V;
DIV ivn,ivmod; 
void init(){
	V=m+10,initC(V);
	ivn.init(n),ivmod.init(mod);
	For(q,1,n-1)
		For(p,0,q){
			int i=p*m/q;
			if(!sum[i])sum[i]=1,frac[i]=p*n+q;
		}
	For(i,1,m)sum[i]+=sum[i-1];
	For(i,0,m)if(frac[i])f[len++]=frac[i];
}
modint inv(int a){
	int j=sum[1ll*a*m/ivmod],p,q;
	if(j<len){
		p=f[j]/ivn,q=f[j]-p*n;
		ll t=1ll*a*q-1ll*p*mod;
		if(abs(t)<=V)return (t>0?iv[t]:-iv[-t])*q;
	}
	--j;
	if(j>=0){
		p=f[j]/ivn,q=f[j]-p*n;
		ll t=1ll*a*q-1ll*p*mod;
		if(abs(t)<=V)return (t>0?iv[t]:-iv[-t])*q;
	}
	return -1;
}

}

void init(int p){
	Inv::init(); 
}
int query(int x){
	int res=(Inv::inv(x)).x;
	return res;
}

Details

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:74:9: error: ‘ull’ does not name a type; did you mean ‘ll’?
   74 |         ull x;
      |         ^~~
      |         ll
answer.code: In member function ‘void DIV::init(int)’:
answer.code:75:35: error: ‘x’ was not declared in this scope
   75 |         inline void init(int v) { x = -1ull / v + 1; }
      |                                   ^
answer.code: At global scope:
answer.code:77:8: error: ‘ull’ does not name a type; did you mean ‘ll’?
   77 | inline ull operator / (const ull & x, const DIV & y) {
      |        ^~~
      |        ll
answer.code: In function ‘modint Inv::inv(int)’:
answer.code:98:26: error: no match for ‘operator/’ (operand types are ‘long long int’ and ‘DIV’)
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                   ~~~~~~~^~~~~~
      |                        |  |
      |                        |  DIV
      |                        long long int
In file included from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from answer.code:2:
/usr/include/c++/13/complex:425:5: note: candidate: ‘template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const complex<_Tp>&)’
  425 |     operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/13/complex:425:5: note:   template argument deduction/substitution failed:
answer.code:98:27: note:   mismatched types ‘const std::complex<_Tp>’ and ‘long long int’
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                           ^~~~~
/usr/include/c++/13/complex:434:5: note: candidate: ‘template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const _Tp&)’
  434 |     operator/(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/13/complex:434:5: note:   template argument deduction/substitution failed:
answer.code:98:27: note:   mismatched types ‘const std::complex<_Tp>’ and ‘long long int’
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                           ^~~~~
/usr/include/c++/13/complex:443:5: note: candidate: ‘template<class _Tp> std::complex<_Tp> std::operator/(const _Tp&, const complex<_Tp>&)’
  443 |     operator/(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/13/complex:443:5: note:   template argument deduction/substitution failed:
answer.code:98:27: note:   ‘DIV’ is not derived from ‘const std::complex<_Tp>’
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                           ^~~~~
In file included from /usr/include/c++/13/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:166:
/usr/include/c++/13/bits/valarray_after.h:408:5: note: candidate: ‘template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)’
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
answer.code:98:27: note:   mismatched types ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ and ‘long long int’
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                           ^~~~~
/usr/include/c++/13/bits/valarray_after.h:408:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)’
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/valarray_after.h:408:5: note:   template argument deduction/substitution failed:
answer.code:98:27: note:   mismatched types ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ and ‘long long int’
   98 |         int j=sum[1ll*a*m/ivmod],p,q;
      |                           ^~~~~
/usr/include/c++/13/bits/valarray_after.h:408:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)’
  408 |     _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides)
  ...