結果

問題 No.645 Count Permutation
ユーザー 👑 kmjpkmjp
提出日時 2018-02-02 22:53:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,415 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 151,888 KB
実行使用メモリ 6,080 KB
最終ジャッジ日時 2023-08-30 02:24:52
合計ジャッジ時間 9,627 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
5,780 KB
testcase_01 AC 129 ms
5,744 KB
testcase_02 AC 132 ms
5,952 KB
testcase_03 WA -
testcase_04 AC 129 ms
5,748 KB
testcase_05 AC 129 ms
5,864 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 309 ms
5,744 KB
testcase_22 WA -
testcase_23 AC 130 ms
5,720 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 322 ms
6,024 KB
testcase_32 AC 186 ms
5,744 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,L,R;
ll mo=1000000007;

ll fact[101010],factr[101010],rev[101010];
ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


vector<int> LIS(vector<int> v) {
	int i,N=v.size();
	vector<int> dp(N,1<<30),id(N);
	FOR(i,v.size()) {
		id[i] = lower_bound(dp.begin(),dp.end(),v[i]) - dp.begin();
		dp[id[i]] = v[i];
	}
	int nl = *max_element(id.begin(),id.end());
	vector<int> ret(nl+1);
	FOR(i,N) if(id[N-1-i] == nl) ret[nl--] = v[N-1-i];
	return ret;
}

ll dp[65];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=factr[0]=1;
	for(i=1;i<=100100;i++) {
		fact[i]=fact[i-1]*i%mo;
		factr[i]=modpow(fact[i]);
		rev[i]=modpow(i);
	}
	
	map<vector<int>,vector<vector<int>>> M;
	cin>>N>>L>>R;
	dp[1]=fact[N-1];
	for(i=2;i<=N-1;i++) {
		for(j=63;j>=1;j--) {
			(dp[j+1]+=dp[j]*rev[i])%=mo;
			dp[j]=(dp[j]-dp[j]*rev[i]%mo+mo)%mo;
		}
	}
	/*
	ll X=0,Y=0;
	for(i=1;i<=10;i++) {
		cout<<i<<" "<<dp[i]<<" "<<(dp[i]<<i)<<endl;
		X+=dp[i];
		Y+=(dp[i]<<i);
	}
	cout<<X<<"  "<<Y<<endl;
	*/
	ll ret=0;
	for(i=1;i<=61;i++) if(L<=1<<(i-1) && 1<<(i-1)<=R) ret+=dp[i];
	if(L==0) ret+=fact[N]-fact[N-1];
	cout<<ret%mo<<endl;
	
#if 0
	vector<int> A;
	FOR(i,N) A.push_back(i+1);
	do {
		vector<int> B=A;
		FOR(i,N-1) if(B[i]>B[i+1]) swap(B[i],B[i+1]);
		M[B].push_back(A);
		/*
		FORR(v,A) cout<<v;
		cout<<" ";
		FORR(v,B) cout<<v;
		cout<<endl;
		*/
	} while(next_permutation(ALL(A)));
	
	map<int,int> R;
	FORR(b,M) {
		FORR(v,b.first) cout<<v;
		cout<<" "<<b.second.size()<<"    "<<LIS(b.first).size()<<endl;
		R[b.second.size()]++;
		/*
		FORR(v,b.second) {
			cout<<"  ";
			FORR(vv,v) cout<<vv;
			cout<<endl;
		}
		*/
	}
	FORR(r,R) cout<<r.first<<" "<<r.second<<"   "<<r.first*r.second<<endl;
	*/
#endif
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0