e62379df86 2021-05-22 kinaba: #include <iostream> e62379df86 2021-05-22 kinaba: #include <sstream> e62379df86 2021-05-22 kinaba: #include <iomanip> e62379df86 2021-05-22 kinaba: #include <vector> e62379df86 2021-05-22 kinaba: #include <string> e62379df86 2021-05-22 kinaba: #include <map> e62379df86 2021-05-22 kinaba: #include <set> e62379df86 2021-05-22 kinaba: #include <algorithm> e62379df86 2021-05-22 kinaba: #include <numeric> e62379df86 2021-05-22 kinaba: #include <iterator> e62379df86 2021-05-22 kinaba: #include <functional> e62379df86 2021-05-22 kinaba: #include <complex> e62379df86 2021-05-22 kinaba: #include <queue> e62379df86 2021-05-22 kinaba: #include <stack> e62379df86 2021-05-22 kinaba: #include <cmath> e62379df86 2021-05-22 kinaba: #include <cassert> e62379df86 2021-05-22 kinaba: #include <tuple> e62379df86 2021-05-22 kinaba: using namespace std; e62379df86 2021-05-22 kinaba: typedef long long LL; e62379df86 2021-05-22 kinaba: typedef complex<double> CMP; e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: class TheUltimatePackages { public: e62379df86 2021-05-22 kinaba: vector <int> count(int N, int D, vector <int> Xprefix, vector <int> Yprefix, int L, int seed) e62379df86 2021-05-22 kinaba: { e62379df86 2021-05-22 kinaba: vector<int> X(D), Y(D); e62379df86 2021-05-22 kinaba: int XL = Xprefix.size(); e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: for (int i = 0; i<XL; ++i) { e62379df86 2021-05-22 kinaba: X[i] = Xprefix[i]; e62379df86 2021-05-22 kinaba: Y[i] = Yprefix[i]; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: long long state = seed; e62379df86 2021-05-22 kinaba: for (int i = XL; i<D; ++i) { e62379df86 2021-05-22 kinaba: state = (state * 1103515245 + 12345) % (1LL << 31); e62379df86 2021-05-22 kinaba: int elen = 1 + state%L; e62379df86 2021-05-22 kinaba: state = (state * 1103515245 + 12345) % (1LL << 31); e62379df86 2021-05-22 kinaba: Y[i] = state % (N - elen); e62379df86 2021-05-22 kinaba: X[i] = Y[i] + elen; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: vector<int> maxdep(N, -1); e62379df86 2021-05-22 kinaba: for (int i = 0; i < D; ++i) e62379df86 2021-05-22 kinaba: maxdep[X[i]] = max(maxdep[X[i]], Y[i]); e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: vector<int> deped_by_all_larger; e62379df86 2021-05-22 kinaba: int cur = N - 1; e62379df86 2021-05-22 kinaba: for (int v = N - 1; v >= 0; --v) { e62379df86 2021-05-22 kinaba: if (v == cur) e62379df86 2021-05-22 kinaba: deped_by_all_larger.push_back(v); e62379df86 2021-05-22 kinaba: if (maxdep[v] < cur) e62379df86 2021-05-22 kinaba: cur = maxdep[v]; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: vector<int> mindep(N, N); e62379df86 2021-05-22 kinaba: for (int i = 0; i < D; ++i) e62379df86 2021-05-22 kinaba: mindep[Y[i]] = min(mindep[Y[i]], X[i]); e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: set<int> deped_by_all_smaller; e62379df86 2021-05-22 kinaba: cur = 0; e62379df86 2021-05-22 kinaba: for (int v = 0; v <= N-1; ++v) { e62379df86 2021-05-22 kinaba: if (v == cur) e62379df86 2021-05-22 kinaba: deped_by_all_smaller.insert(v); e62379df86 2021-05-22 kinaba: if (cur < mindep[v]) e62379df86 2021-05-22 kinaba: cur = mindep[v]; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: int sum = 0; e62379df86 2021-05-22 kinaba: int cnt = 0; e62379df86 2021-05-22 kinaba: for (int v : deped_by_all_larger) e62379df86 2021-05-22 kinaba: if (deped_by_all_smaller.count(v)) { e62379df86 2021-05-22 kinaba: sum += v; e62379df86 2021-05-22 kinaba: cnt += 1; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: vector<int> ans = { cnt, sum }; e62379df86 2021-05-22 kinaba: return ans; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: }; e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: // BEGIN CUT HERE e62379df86 2021-05-22 kinaba: #include <ctime> e62379df86 2021-05-22 kinaba: double start_time; string timer() e62379df86 2021-05-22 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e62379df86 2021-05-22 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e62379df86 2021-05-22 kinaba: { os << "{ "; e62379df86 2021-05-22 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e62379df86 2021-05-22 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e62379df86 2021-05-22 kinaba: void verify_case(const vector <int>& Expected, const vector <int>& Received) { e62379df86 2021-05-22 kinaba: bool ok = (Expected == Received); e62379df86 2021-05-22 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e62379df86 2021-05-22 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } e62379df86 2021-05-22 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e62379df86 2021-05-22 kinaba: #define END verify_case(_, TheUltimatePackages().count(N, D, Xprefix, Yprefix, L, seed));} e62379df86 2021-05-22 kinaba: int main(){ e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: CASE(0) e62379df86 2021-05-22 kinaba: int N = 5; e62379df86 2021-05-22 kinaba: int D = 4; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {1, 3, 2, 4}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {0, 2, 1, 3}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 47; e62379df86 2021-05-22 kinaba: int __[] = {5, 10 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(1) e62379df86 2021-05-22 kinaba: int N = 5; e62379df86 2021-05-22 kinaba: int D = 6; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {1, 2, 3, 4, 4, 4}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {0, 0, 0, 1, 3, 2}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 64; e62379df86 2021-05-22 kinaba: int __[] = {2, 4 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(2) e62379df86 2021-05-22 kinaba: int N = 5; e62379df86 2021-05-22 kinaba: int D = 4; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {2, 2, 3, 4}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {0, 1, 2, 2}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 32532; e62379df86 2021-05-22 kinaba: int __[] = {1, 2 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(3) e62379df86 2021-05-22 kinaba: int N = 4; e62379df86 2021-05-22 kinaba: int D = 3; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {3, 3, 2}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {0, 2, 1}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 2555; e62379df86 2021-05-22 kinaba: int __[] = {1, 3 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(4) e62379df86 2021-05-22 kinaba: int N = 7; e62379df86 2021-05-22 kinaba: int D = 0; e62379df86 2021-05-22 kinaba: vector <int> Xprefix; e62379df86 2021-05-22 kinaba: vector <int> Yprefix; e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 0; e62379df86 2021-05-22 kinaba: int __[] = {0, 0 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(5) e62379df86 2021-05-22 kinaba: int N = 2; e62379df86 2021-05-22 kinaba: int D = 4; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {1, 1, 1, 1}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {0, 0, 0, 0}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 1; e62379df86 2021-05-22 kinaba: int seed = 0; e62379df86 2021-05-22 kinaba: int __[] = {2, 1 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(6) e62379df86 2021-05-22 kinaba: int N = 7; e62379df86 2021-05-22 kinaba: int D = 12; e62379df86 2021-05-22 kinaba: int Xprefix_[] = {2, 3, 4}; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = {1, 2, 3}; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = 5; e62379df86 2021-05-22 kinaba: int seed = 4747; e62379df86 2021-05-22 kinaba: int __[] = {0, 0 }; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: /* e62379df86 2021-05-22 kinaba: CASE(7) e62379df86 2021-05-22 kinaba: int N = ; e62379df86 2021-05-22 kinaba: int D = ; e62379df86 2021-05-22 kinaba: int Xprefix_[] = ; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = ; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = ; e62379df86 2021-05-22 kinaba: int seed = ; e62379df86 2021-05-22 kinaba: int __[] = ; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(8) e62379df86 2021-05-22 kinaba: int N = ; e62379df86 2021-05-22 kinaba: int D = ; e62379df86 2021-05-22 kinaba: int Xprefix_[] = ; e62379df86 2021-05-22 kinaba: vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_)); e62379df86 2021-05-22 kinaba: int Yprefix_[] = ; e62379df86 2021-05-22 kinaba: vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_)); e62379df86 2021-05-22 kinaba: int L = ; e62379df86 2021-05-22 kinaba: int seed = ; e62379df86 2021-05-22 kinaba: int __[] = ; e62379df86 2021-05-22 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: */ e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: // END CUT HERE