Artifact Content
Not logged in

Artifact a0907284c078940eff388312e331b13b7d287ada


#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; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator/(mint x, mint y) { return x/=y; }

class TriangleTriples { public:
	int count(int A, int B, int C)
	{
		return (mint(A)*B*C - cut(A,B,C) - cut(B,C,A) - cut(C,A,B)).val;
	}

	// #{(a,b,c)<=(A,B,C) | a+b<=c}
	mint cut(LL A, LL B, LL C)
	{
		if(A>B) swap(A,B);

		//----------------------------
		// Sigma
		// #{a+b <= 1}
		// #{a+b <= 2}
		// ...
		// #{a+b <= C}
		//----------------------------
		// Sigma
		// #{a+b == 1} * C
		// #{a+b == 2} * C-1
		// ...
		// #{a+b == C} * 1
		//----------------------------
		// where
		//
		//  #{a+b == k}
		//=
		//   k-1       for        k <= A
		//   A         for  A+1<= k <= B
		//   A-(k-B)+1 for  B+1<= k <= A+B
		//   0         for  A+B<  k
		//----------------------------

		mint total = 0;

		//for(int k=1; k<=min(C,A); ++k)
		//	total += mint(k-1) * (C-k+1);
		{
			LL x = min(C,A);
			total += mint(0+x-1)*x/2 * C - mint(x-1)*x*(2*x-1)/6;
		}

		// for(int k=A+1; k<=min(C,B); ++k)
		// 	total += mint(A) * (C-k+1);
		if(A+1 <= min(C,B)) {
			LL x = A+1, y = min(C,B);
			total += mint(A) * (C-x+1+C-y+1) * (y-x+1) / 2;
		}

		//for(int k=B+1; k<=min(C,A+B); ++k)
		//	total += mint(A-(k-B)+1) * (C-k+1);

		if(B+1 <= min(C,A+B)) {
			LL X = min(C,A+B)-B, D = C-B;
			//for(LL k=0; k<=X; ++k)
			//	total += mint(A-k)*(D-k);

			LL E = abs(D-A);
			//for(LL k=0; k<=X; ++k)
			//	total += mint(k)*(k+E);
			total += mint(X)*(X+1)/2*E + mint(X)*(X+1)*(2*X+1)/6;
		}
		return total;
	}
};

// 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 int& Expected, const 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(_, TriangleTriples().count(A, B, C));}
int main(){

CASE(0)
	int A = 1; 
	int B = 10; 
	int C = 20; 
	int _ = 10; 
END
CASE(2)
	int A = 10; 
	int B = 10; 
	int C = 10; 
	int _ = 505; 
END
CASE(3)
	int A = 1; 
	int B = 1; 
	int C = 1; 
	int _ = 1; 
END
CASE(1)
	int A = 2; 
	int B = 2; 
	int C = 1000000000; 
	int _ = 6; 
END
CASE(4)
	int A = 123456789; 
	int B = 987654321; 
	int C = 555555555; 
	int _ = 64296241; 
END
CASE(4)
	int A = 123456789; 
	int B = 555555555; 
	int C = 987654321; 
	int _ = 64296241; 
END
CASE(4)
	int A = 555555555; 
	int B = 987654321; 
	int C = 123456789; 
	int _ = 64296241; 
END
/*
CASE(5)
	int A = ; 
	int B = ; 
	int C = ; 
	int _ = ; 
END
CASE(6)
	int A = ; 
	int B = ; 
	int C = ; 
	int _ = ; 
END
*/
}
// END CUT HERE