a57e4e95ff 2016-04-15 kinaba: #include <iostream> a57e4e95ff 2016-04-15 kinaba: #include <sstream> a57e4e95ff 2016-04-15 kinaba: #include <iomanip> a57e4e95ff 2016-04-15 kinaba: #include <vector> a57e4e95ff 2016-04-15 kinaba: #include <string> a57e4e95ff 2016-04-15 kinaba: #include <map> a57e4e95ff 2016-04-15 kinaba: #include <set> a57e4e95ff 2016-04-15 kinaba: #include <algorithm> a57e4e95ff 2016-04-15 kinaba: #include <numeric> a57e4e95ff 2016-04-15 kinaba: #include <iterator> a57e4e95ff 2016-04-15 kinaba: #include <functional> a57e4e95ff 2016-04-15 kinaba: #include <complex> a57e4e95ff 2016-04-15 kinaba: #include <queue> a57e4e95ff 2016-04-15 kinaba: #include <stack> a57e4e95ff 2016-04-15 kinaba: #include <cmath> a57e4e95ff 2016-04-15 kinaba: #include <cassert> a57e4e95ff 2016-04-15 kinaba: #include <tuple> a57e4e95ff 2016-04-15 kinaba: using namespace std; a57e4e95ff 2016-04-15 kinaba: typedef long long LL; a57e4e95ff 2016-04-15 kinaba: typedef complex<double> CMP; a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: static const unsigned MODVAL = 1000000007; a57e4e95ff 2016-04-15 kinaba: struct mint a57e4e95ff 2016-04-15 kinaba: { a57e4e95ff 2016-04-15 kinaba: unsigned val; a57e4e95ff 2016-04-15 kinaba: mint():val(0){} a57e4e95ff 2016-04-15 kinaba: mint(int x):val(x%MODVAL) {} a57e4e95ff 2016-04-15 kinaba: mint(unsigned x):val(x%MODVAL) {} a57e4e95ff 2016-04-15 kinaba: mint(LL x):val(x%MODVAL) {} a57e4e95ff 2016-04-15 kinaba: }; a57e4e95ff 2016-04-15 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } a57e4e95ff 2016-04-15 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } a57e4e95ff 2016-04-15 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } a57e4e95ff 2016-04-15 kinaba: mint operator+(mint x, mint y) { return x+=y; } a57e4e95ff 2016-04-15 kinaba: mint operator-(mint x, mint y) { return x-=y; } a57e4e95ff 2016-04-15 kinaba: mint operator*(mint x, mint y) { return x*=y; } a57e4e95ff 2016-04-15 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: class CyclesNumber { public: a57e4e95ff 2016-04-15 kinaba: vector <int> getExpectation(vector <int> n, vector <int> m) a57e4e95ff 2016-04-15 kinaba: { a57e4e95ff 2016-04-15 kinaba: map<int, set<int>> q; a57e4e95ff 2016-04-15 kinaba: for(int i=0; i<n.size(); ++i) a57e4e95ff 2016-04-15 kinaba: q[n[i]].insert(m[i]); a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: map<pair<int,int>, int> ans; a57e4e95ff 2016-04-15 kinaba: T(*max_element(n.begin(), n.end()), q, ans); a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: vector<int> result; a57e4e95ff 2016-04-15 kinaba: for(int i=0; i<n.size(); ++i) a57e4e95ff 2016-04-15 kinaba: result.push_back(ans[make_pair(n[i], m[i])]); a57e4e95ff 2016-04-15 kinaba: return result; a57e4e95ff 2016-04-15 kinaba: } a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: void T(int n, map<int,set<int>>& q, map<pair<int,int>,int>& ans) a57e4e95ff 2016-04-15 kinaba: { a57e4e95ff 2016-04-15 kinaba: vector<mint> Si; a57e4e95ff 2016-04-15 kinaba: Si.push_back(0); a57e4e95ff 2016-04-15 kinaba: Si.push_back(1); a57e4e95ff 2016-04-15 kinaba: for(int i=1; i<=n; ++i) a57e4e95ff 2016-04-15 kinaba: { a57e4e95ff 2016-04-15 kinaba: for(int m: q[i]) { a57e4e95ff 2016-04-15 kinaba: mint total = 0; a57e4e95ff 2016-04-15 kinaba: for(int f=0; f<Si.size(); ++f) a57e4e95ff 2016-04-15 kinaba: total += POW(f, m) * Si[f]; a57e4e95ff 2016-04-15 kinaba: ans[make_pair(i,m)] = total.val; a57e4e95ff 2016-04-15 kinaba: } a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: Si.resize(Si.size()+1); a57e4e95ff 2016-04-15 kinaba: for(int k=Si.size()-1; k>=1; --k) a57e4e95ff 2016-04-15 kinaba: Si[k] = Si[k]*i + Si[k-1]; a57e4e95ff 2016-04-15 kinaba: } a57e4e95ff 2016-04-15 kinaba: } a57e4e95ff 2016-04-15 kinaba: }; a57e4e95ff 2016-04-15 kinaba: a57e4e95ff 2016-04-15 kinaba: // BEGIN CUT HERE a57e4e95ff 2016-04-15 kinaba: #include <ctime> a57e4e95ff 2016-04-15 kinaba: double start_time; string timer() a57e4e95ff 2016-04-15 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } a57e4e95ff 2016-04-15 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) a57e4e95ff 2016-04-15 kinaba: { os << "{ "; a57e4e95ff 2016-04-15 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) a57e4e95ff 2016-04-15 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } a57e4e95ff 2016-04-15 kinaba: void verify_case(const vector <int>& Expected, const vector <int>& Received) { a57e4e95ff 2016-04-15 kinaba: bool ok = (Expected == Received); a57e4e95ff 2016-04-15 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; a57e4e95ff 2016-04-15 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } a57e4e95ff 2016-04-15 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); a57e4e95ff 2016-04-15 kinaba: #define END verify_case(_, CyclesNumber().getExpectation(n, m));} a57e4e95ff 2016-04-15 kinaba: int main(){ a57e4e95ff 2016-04-15 kinaba: CASE(0) a57e4e95ff 2016-04-15 kinaba: int n_[] = {2}; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = {2}; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = {5 }; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: CASE(1) a57e4e95ff 2016-04-15 kinaba: int n_[] = {3}; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = {0}; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = {6 }; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: CASE(2) a57e4e95ff 2016-04-15 kinaba: int n_[] = {1, 2, 3}; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = {1, 3, 3}; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = {1, 9, 53 }; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: CASE(3) a57e4e95ff 2016-04-15 kinaba: int n_[] = {10, 20, 30}; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = {10, 20, 30}; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = {586836447, 544389755, 327675273 }; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: CASE(4) a57e4e95ff 2016-04-15 kinaba: int n_[] = {100000}; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = {300}; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = {-1}; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: /* a57e4e95ff 2016-04-15 kinaba: CASE(5) a57e4e95ff 2016-04-15 kinaba: int n_[] = ; a57e4e95ff 2016-04-15 kinaba: vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); a57e4e95ff 2016-04-15 kinaba: int m_[] = ; a57e4e95ff 2016-04-15 kinaba: vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); a57e4e95ff 2016-04-15 kinaba: int __[] = ; a57e4e95ff 2016-04-15 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); a57e4e95ff 2016-04-15 kinaba: END a57e4e95ff 2016-04-15 kinaba: */ a57e4e95ff 2016-04-15 kinaba: } a57e4e95ff 2016-04-15 kinaba: // END CUT HERE