QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210654 | #5749. Directed Vertex Cacti | ExplodingKonjac | AC ✓ | 14ms | 3736kb | C++20 | 7.5kb | 2023-10-11 18:15:03 | 2023-10-11 18:15:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
private:
void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
template<typename T>
void __write(T x)
{
char stk[numeric_limits<T>::digits10+1],*top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
~FastOutput() { flush(); }
void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
FastOutput &operator <<(char x)
{ return __putc(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
FastOutput &operator <<(const std::string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(const T &x)
{ return __write(x),*this; }
template<typename ...T>
void writesp(const T &...x)
{ std::initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
void writeln(const T &...x)
{ std::initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
template<typename Iter>
void writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
void writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
private:
bool __eof;
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char get()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void unget(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf[--buf_p]=c;
#else
ungetc(c,target);
#endif
}
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=get()));return *this; }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=get()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=get();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
return unget(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=get()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=get());
return unget(*s),*s='\0',*this;
}
FastInput &operator >>(std::string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=get()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
unget(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &...x)
{ std::initializer_list<int>{(this->operator>>(x),0)...}; }
template<typename Iter>
void read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) void()
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace Math
{
template<typename Derived>
class ModintBase
{
protected:
int val;
private:
template<typename T>
constexpr enable_if_t<is_integral<T>::value,T> __inv(T a,T b)const
{ T x=0,y=1,t=0;for(;a;t=b/a,std::swap(a,b-=t*a),std::swap(y,x-=t*y));return x; }
template<typename T>
constexpr enable_if_t<is_integral<T>::value,T> __fix(T x)const
{ return static_cast<const Derived*>(this)->fix(x); }
constexpr static ModintBase __unfixed(int x)
{ return reinterpret_cast<ModintBase&>(x); }
#define DEF_OP1(op) \
friend constexpr ModintBase operator op(const ModintBase &lhs,const ModintBase &rhs)\
{ return ModintBase(lhs)op##=rhs; }\
ModintBase &operator op##=(const ModintBase &rhs)
#define DEF_OP2(op) \
constexpr ModintBase operator op(int)\
{ ModintBase res(*this);return op(*this),res; }\
constexpr ModintBase &operator op()
#define DEF_OP3(op) \
constexpr ModintBase operator op()const
#define DEF_OP4(op) \
friend constexpr bool operator op(const ModintBase &lhs,const ModintBase &rhs) \
{ return lhs.val op rhs.val; }
#define MOD static_cast<const Derived*>(this)->getMod()
public:
constexpr ModintBase(): val(0) {}
template<typename T>
constexpr ModintBase(const T &x): val(__fix(x)) {}
constexpr int operator ()()const { return val; }
DEF_OP1(+) { return (val+=rhs.val)>=MOD?val-=MOD:0,*this; }
DEF_OP1(-) { return (val-=rhs.val)<0?val+=MOD:0,*this; }
DEF_OP1(*) { return val=__fix(1ll*val*rhs.val),*this; }
DEF_OP1(/) { return val=__fix(1ll*val*__inv(rhs.val,MOD)),*this; }
DEF_OP2(++) { return (++val)>=MOD?val-=MOD:0,*this; }
DEF_OP2(--) { return (--val)<0?val+=MOD:0,*this; }
DEF_OP3(+) { return *this; }
DEF_OP3(-) { return __unfixed(val?MOD-val:0); }
DEF_OP4(==) DEF_OP4(!=) DEF_OP4(<) DEF_OP4(>) DEF_OP4(<=) DEF_OP4(>=)
constexpr ModintBase inv()const
{ return ModintBase(__inv(val,MOD)); }
template<typename T>
friend inline constexpr enable_if_t<is_integral<T>::value,Derived> qpow(Derived x,T y)
{ Derived res(1);for(;y;x*=x,y>>=1)if(y&1)res*=x;return res; }
#undef DEF_OP1
#undef DEF_OP2
#undef DEF_OP3
#undef DEF_OP4
#undef MOD
};
class FastMod
{
private:
using ULL=uint64_t;
using U128=__uint128_t;
ULL p,m;
public:
constexpr FastMod(): p(0),m(0) {}
constexpr FastMod(ULL p): p(p),m((U128(1)<<64)/p) {}
constexpr ULL getp()const { return p; }
constexpr ULL operator()(ULL a)const
{ ULL q=(U128(m)*a)>>64,r=a-q*p;return r>=p?r-p:r; }
};
// Modint for dynamic MOD
class DModint: public ModintBase<DModint>
{
private:
using BaseT=ModintBase<DModint>;
static FastMod R;
friend BaseT;
template<typename T> static constexpr T fix(T x)
{ return x<0?R.getp()-R(-x):R(x); }
public:
template<typename ...T>
constexpr DModint(T ...x): BaseT(x...){}
static constexpr void setMod(int mod) { R=FastMod(mod); }
static constexpr int getMod() { return R.getp(); }
};
FastMod DModint::R{};
// Modint for static MOD
template<int MOD>
class SModint: public ModintBase<SModint<MOD>>
{
private:
using BaseT=ModintBase<SModint<MOD>>;
friend BaseT;
template<typename T> static constexpr T fix(T x)
{ return (x%=MOD)<0?x+MOD:x; }
public:
template<typename ...T>
constexpr SModint(T ...x): BaseT(x...) {}
static constexpr int getMod() { return MOD; }
};
} // namespace Math
constexpr int MOD=1e9+9;
using Mint=Math::SModint<MOD>;
int n,m;
int main()
{
qin>>n>>m;
Mint c1(1),c2(1),c3(1);
for(LL i=0;i<m;i++) c1*=(n*LL(n-1)/2-i);
for(int i=1;i<=m;i++) c2*=i;
for(int i=1;i<=n;i++) c3*=i;
Mint ans=c1/c2*c3;
qout<<ans()<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
3 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
4 4
output:
360
result:
ok 1 number(s): "360"
Test #3:
score: 0
Accepted
time: 4ms
memory: 3672kb
input:
39847 348708
output:
983575456
result:
ok 1 number(s): "983575456"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
3 2
output:
18
result:
ok 1 number(s): "18"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 3
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 4
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 9ms
memory: 3580kb
input:
3 1000000
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
4 1
output:
144
result:
ok 1 number(s): "144"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 2
output:
360
result:
ok 1 number(s): "360"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 3
output:
480
result:
ok 1 number(s): "480"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
4 5
output:
144
result:
ok 1 number(s): "144"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 6
output:
24
result:
ok 1 number(s): "24"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 1
output:
1200
result:
ok 1 number(s): "1200"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
5 2
output:
5400
result:
ok 1 number(s): "5400"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 3
output:
14400
result:
ok 1 number(s): "14400"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
5 4
output:
25200
result:
ok 1 number(s): "25200"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 5
output:
30240
result:
ok 1 number(s): "30240"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
5 6
output:
25200
result:
ok 1 number(s): "25200"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
5 7
output:
14400
result:
ok 1 number(s): "14400"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 8
output:
5400
result:
ok 1 number(s): "5400"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 9
output:
1200
result:
ok 1 number(s): "1200"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 10
output:
120
result:
ok 1 number(s): "120"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
1000 1
output:
533396879
result:
ok 1 number(s): "533396879"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1000 100
output:
199484478
result:
ok 1 number(s): "199484478"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1000 10000
output:
656650652
result:
ok 1 number(s): "656650652"
Test #27:
score: 0
Accepted
time: 6ms
memory: 3668kb
input:
1000 1000000
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 8ms
memory: 3672kb
input:
535164 619302
output:
721871396
result:
ok 1 number(s): "721871396"
Test #29:
score: 0
Accepted
time: 14ms
memory: 3668kb
input:
1000000 1000000
output:
580712335
result:
ok 1 number(s): "580712335"
Test #30:
score: 0
Accepted
time: 7ms
memory: 3580kb
input:
1000000 234534
output:
546630669
result:
ok 1 number(s): "546630669"
Test #31:
score: 0
Accepted
time: 10ms
memory: 3712kb
input:
234523 1000000
output:
127869098
result:
ok 1 number(s): "127869098"
Test #32:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
44722 10000
output:
0
result:
ok 1 number(s): "0"