Artifact Content
Not logged in

Artifact eeebdace328178c2d34b9590b0a63f1e21a4a066


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }

class CyclesNumber { public:
	vector <int> getExpectation(vector <int> n, vector <int> m)
	{
		map<int, set<int>> q;
		for(int i=0; i<n.size(); ++i)
			q[n[i]].insert(m[i]);

		map<pair<int,int>, int> ans;
		T(*max_element(n.begin(), n.end()), q, ans);

		vector<int> result;
		for(int i=0; i<n.size(); ++i)
			result.push_back(ans[make_pair(n[i], m[i])]);
		return result;
	}

	void T(int n, map<int,set<int>>& q, map<pair<int,int>,int>& ans)
	{
		vector<mint> Si;
		Si.push_back(0);
		Si.push_back(1);
		for(int i=1; i<=n; ++i)
		{
			for(int m: q[i]) {
				mint total = 0;
				for(int f=0; f<Si.size(); ++f)
					total += POW(f, m) * Si[f];
				ans[make_pair(i,m)] = total.val;
			}

			Si.resize(Si.size()+1);
			for(int k=Si.size()-1; k>=1; --k)
				Si[k] = Si[k]*i + Si[k-1];
		}
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, CyclesNumber().getExpectation(n, m));}
int main(){
CASE(0)
	int n_[] = {2};
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
	int m_[] = {2};
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
	int __[] = {5 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int n_[] = {3};
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
	int m_[] = {0};
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
	int __[] = {6 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int n_[] = {1, 2, 3};
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
	int m_[] = {1, 3, 3};
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
	int __[] = {1, 9, 53 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int n_[] = {10, 20, 30};
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
	int m_[] = {10, 20, 30};
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
	int __[] = {586836447, 544389755, 327675273 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
    int n_[] = {100000};
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
    int m_[] = {300};
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
    int __[] = {-1};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(5)
	int n_[] = ;
	  vector <int> n(n_, n_+sizeof(n_)/sizeof(*n_)); 
	int m_[] = ;
	  vector <int> m(m_, m_+sizeof(m_)/sizeof(*m_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE