rt,在 P3803(FFT 板题)和 P1919(大整数乘法板题)的题解中均有提及 std::complex 运行非常慢,可能 TLE 或被出题人卡,但实际我自己测试的结果是效率所差无几,这是怎么回事?考虑到可能是实现的问题,这里贴下我的代码:
using f64=double;
class complex{
f64 a,b;
public:
constexpr complex(const complex& x):a(x.a),b(x.b){}
constexpr complex():a(0),b(0){}
constexpr complex(const f64& x,const f64& y):a(x),b(y){}
constexpr complex(const f64& x):a(x),b(0){}
complex operator=(const f64& x){return a=x;}
complex operator=(const complex& x){
a=x.a;b=x.b;
return *this;
}
complex operator+(const complex& x)const{
return complex(a+x.a,b+x.b);
}
complex operator-(const complex& x)const{
return complex(a-x.a,b-x.b);
}
complex operator*(const complex& x)const{
return complex(a*x.a-b*x.b,a*x.b+b*x.a);
}
complex operator+=(const complex& x){
a+=x.a;
b+=x.b;
return *this;
}
complex operator-=(const complex& x){
a-=x.a;
b-=x.b;
return *this;
}
complex operator*=(const complex& x){
return (*this)=(*this)*x;
}
f64 real()const{return a;}
f64 imag()const{return b;}
f64 real(const f64& x){return a=x;}
f64 imag(const f64& x){return b=x;}
};
constexpr complex conj(const complex& x){return complex(x.real(),-x.imag());}