1a2a57338c 2012-01-20 kinaba: #include <iostream> 1a2a57338c 2012-01-20 kinaba: #include <sstream> 1a2a57338c 2012-01-20 kinaba: #include <iomanip> 1a2a57338c 2012-01-20 kinaba: #include <vector> 1a2a57338c 2012-01-20 kinaba: #include <string> 1a2a57338c 2012-01-20 kinaba: #include <map> 1a2a57338c 2012-01-20 kinaba: #include <set> 1a2a57338c 2012-01-20 kinaba: #include <algorithm> 1a2a57338c 2012-01-20 kinaba: #include <numeric> 1a2a57338c 2012-01-20 kinaba: #include <iterator> 1a2a57338c 2012-01-20 kinaba: #include <functional> 1a2a57338c 2012-01-20 kinaba: #include <complex> 1a2a57338c 2012-01-20 kinaba: #include <queue> 1a2a57338c 2012-01-20 kinaba: #include <stack> 1a2a57338c 2012-01-20 kinaba: #include <cmath> 1a2a57338c 2012-01-20 kinaba: #include <cassert> 1a2a57338c 2012-01-20 kinaba: #include <cstring> 1a2a57338c 2012-01-20 kinaba: #ifdef __GNUC__ 1a2a57338c 2012-01-20 kinaba: #include <ext/hash_map> 1a2a57338c 2012-01-20 kinaba: #define unordered_map __gnu_cxx::hash_map 1a2a57338c 2012-01-20 kinaba: #else 1a2a57338c 2012-01-20 kinaba: #include <unordered_map> 1a2a57338c 2012-01-20 kinaba: #endif 1a2a57338c 2012-01-20 kinaba: using namespace std; 1a2a57338c 2012-01-20 kinaba: typedef long long LL; 1a2a57338c 2012-01-20 kinaba: typedef complex<double> CMP; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: class BigAndSmallAirports { public: 1a2a57338c 2012-01-20 kinaba: long long solve(int Nlo, int Nhi, int Blo, int Bhi, int Slo, int Shi) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: LL cnt = 0; 1a2a57338c 2012-01-20 kinaba: for(int B=Blo; B<=Bhi; ++B) 1a2a57338c 2012-01-20 kinaba: for(int S=Slo; S<=Shi; ++S) 1a2a57338c 2012-01-20 kinaba: if( S < B ) 1a2a57338c 2012-01-20 kinaba: cnt += fast(Nhi, B, S) - fast(Nlo-1, B, S); 1a2a57338c 2012-01-20 kinaba: return cnt; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: LL fast(LL N, LL B, LL S) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: LL cnt = 0; 1a2a57338c 2012-01-20 kinaba: for(LL k=0; k<=N; ++k) { 1a2a57338c 2012-01-20 kinaba: LL Nmin = ((1+B+S)*k - k*k + S-1) / S; 1a2a57338c 2012-01-20 kinaba: if( Nmin < 0 ) { 1a2a57338c 2012-01-20 kinaba: cnt += (N-k+1)*(N-k+2)/2; 1a2a57338c 2012-01-20 kinaba: break; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: Nmin = max(Nmin, k); 1a2a57338c 2012-01-20 kinaba: if( N >= Nmin ) 1a2a57338c 2012-01-20 kinaba: cnt += (N-Nmin+1); 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: return cnt; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: }; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: // BEGIN CUT HERE 1a2a57338c 2012-01-20 kinaba: #include <ctime> 1a2a57338c 2012-01-20 kinaba: double start_time; string timer() 1a2a57338c 2012-01-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1a2a57338c 2012-01-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1a2a57338c 2012-01-20 kinaba: { os << "{ "; 1a2a57338c 2012-01-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1a2a57338c 2012-01-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1a2a57338c 2012-01-20 kinaba: void verify_case(const long long& Expected, const long long& Received) { 1a2a57338c 2012-01-20 kinaba: bool ok = (Expected == Received); 1a2a57338c 2012-01-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1a2a57338c 2012-01-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1a2a57338c 2012-01-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1a2a57338c 2012-01-20 kinaba: #define END verify_case(_, BigAndSmallAirports().solve(Nlo, Nhi, Blo, Bhi, Slo, Shi));} 1a2a57338c 2012-01-20 kinaba: int main(){ 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: CASE(0) 1a2a57338c 2012-01-20 kinaba: int Nlo = 20; 1a2a57338c 2012-01-20 kinaba: int Nhi = 20; 1a2a57338c 2012-01-20 kinaba: int Blo = 3; 1a2a57338c 2012-01-20 kinaba: int Bhi = 3; 1a2a57338c 2012-01-20 kinaba: int Slo = 2; 1a2a57338c 2012-01-20 kinaba: int Shi = 2; 1a2a57338c 2012-01-20 kinaba: long long _ = 21LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(1) 1a2a57338c 2012-01-20 kinaba: int Nlo = 1; 1a2a57338c 2012-01-20 kinaba: int Nhi = 1; 1a2a57338c 2012-01-20 kinaba: int Blo = 10; 1a2a57338c 2012-01-20 kinaba: int Bhi = 10; 1a2a57338c 2012-01-20 kinaba: int Slo = 2; 1a2a57338c 2012-01-20 kinaba: int Shi = 2; 1a2a57338c 2012-01-20 kinaba: long long _ = 1LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(2) 1a2a57338c 2012-01-20 kinaba: int Nlo = 10; 1a2a57338c 2012-01-20 kinaba: int Nhi = 10; 1a2a57338c 2012-01-20 kinaba: int Blo = 8; 1a2a57338c 2012-01-20 kinaba: int Bhi = 8; 1a2a57338c 2012-01-20 kinaba: int Slo = 3; 1a2a57338c 2012-01-20 kinaba: int Shi = 3; 1a2a57338c 2012-01-20 kinaba: long long _ = 6LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(3) 1a2a57338c 2012-01-20 kinaba: int Nlo = 10; 1a2a57338c 2012-01-20 kinaba: int Nhi = 100; 1a2a57338c 2012-01-20 kinaba: int Blo = 13; 1a2a57338c 2012-01-20 kinaba: int Bhi = 15; 1a2a57338c 2012-01-20 kinaba: int Slo = 18; 1a2a57338c 2012-01-20 kinaba: int Shi = 22; 1a2a57338c 2012-01-20 kinaba: long long _ = 0LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(4) 1a2a57338c 2012-01-20 kinaba: int Nlo = 30; 1a2a57338c 2012-01-20 kinaba: int Nhi = 32; 1a2a57338c 2012-01-20 kinaba: int Blo = 8; 1a2a57338c 2012-01-20 kinaba: int Bhi = 10; 1a2a57338c 2012-01-20 kinaba: int Slo = 6; 1a2a57338c 2012-01-20 kinaba: int Shi = 8; 1a2a57338c 2012-01-20 kinaba: long long _ = 768LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(5) 1a2a57338c 2012-01-20 kinaba: int Nlo = 1; 1a2a57338c 2012-01-20 kinaba: int Nhi = 10000000; 1a2a57338c 2012-01-20 kinaba: int Blo = 1; 1a2a57338c 2012-01-20 kinaba: int Bhi = 200; 1a2a57338c 2012-01-20 kinaba: int Slo = 1; 1a2a57338c 2012-01-20 kinaba: int Shi = 200; 1a2a57338c 2012-01-20 kinaba: long long _ = -1LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: /* 1a2a57338c 2012-01-20 kinaba: CASE(6) 1a2a57338c 2012-01-20 kinaba: int Nlo = ; 1a2a57338c 2012-01-20 kinaba: int Nhi = ; 1a2a57338c 2012-01-20 kinaba: int Blo = ; 1a2a57338c 2012-01-20 kinaba: int Bhi = ; 1a2a57338c 2012-01-20 kinaba: int Slo = ; 1a2a57338c 2012-01-20 kinaba: int Shi = ; 1a2a57338c 2012-01-20 kinaba: long long _ = LL; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: */ 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: // END CUT HERE