Artifact Content
Not logged in

Artifact 15a7013bcd9179070ee2cef15a229985862c8478


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

class BuildingAdvertise
{
public:
	long long getMaxArea(vector <int> h, int n) 
	{
		// input
		LL j = 0;
		LL m = h.size();
		vector<LL> R(n);
		for(int i=0; i<n; ++i) {
			R[i] = h[j];
			LL s = (j+1)%m;
			h[j] = ( ( h[j] ^ h[s] ) + 13 ) % 835454957;
			j = s;
		}

		// solve
		vector<int> left(n);
		{
			map<LL, int> h; h[-1] = -1;
			for(int i=0; i<n; ++i) {
				// position of the highest building < R[i]
				map<LL,int>::iterator it = h.lower_bound(R[i]);
				left[i] = (--it)->second+1;
				h.erase( ++it, h.end() );
				h[ R[i] ] = i;
			}
		}
		vector<int> right(n);
		{
			map<LL, int> h; h[-1] = n;
			for(int i=n-1; i>=0; --i) {
				// position of the highest building < R[i]
				map<LL,int>::iterator it = h.lower_bound(R[i]);
				right[i] = (--it)->second-1;
				h.erase( ++it, h.end() );
				h[ R[i] ] = i;
			}
		}
		LL ans = 0;
		for(int i=0; i<n; ++i) {
			LL area = R[i] * (right[i] - left[i] + 1);
			ans = max(ans, area);
		}
		return ans;
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arr0[] = {3,6,5,6,2,4}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; long long Arg2 = 15LL; verify_case(0, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_1() { int Arr0[] = {5,0,7,0,2,6,2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 7; long long Arg2 = 7LL; verify_case(1, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_2() { int Arr0[] = {1048589,2097165}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 100000; long long Arg2 = 104858900000LL; verify_case(2, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_3() { int Arr0[] = {1,7,2,5,3,1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; long long Arg2 = 8LL; verify_case(3, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_4() { int Arr0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 9999; long long Arg2 = 1903656LL; verify_case(4, Arg2, getMaxArea(Arg0, Arg1)); }
// END CUT HERE
};
// BEGIN CUT HERE 
int main() { BuildingAdvertise().run_test(-1); }
// END CUT HERE