Submission #1255061
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
#define INF 1LL<<60
#ifdef _MSC_VER
inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; }
inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); }
#endif
template<class T> struct IRMXQ {
vector<T> A; vector<vector<int> > M, X; int N;
IRMXQ() {}
IRMXQ(const vector<T> &A_) : A(A_) {
N = A.size(); int LOGN = __lg(N) + 1;
M.resize(LOGN); X.resize(LOGN);
for (int i = 0; i<LOGN; i++) { M[i].resize(N); X[i].resize(N); }
for (int j = 0; j<N; j++) M[0][j] = X[0][j] = j;
for (int i = 0; i<LOGN - 1; i++) {
for (int j = 0; j + (1 << i)<N; j++) {
if (A[M[i][j + (1 << i)]] < A[M[i][j]]) M[i + 1][j] = M[i][j + (1 << i)];
else M[i + 1][j] = M[i][j];
if (A[X[i][j]] < A[X[i][j + (1 << i)]]) X[i + 1][j] = X[i][j + (1 << i)];
else X[i + 1][j] = X[i][j];
}
}
}
// 全て[l,r)
T min_v(int l, int r) { return A[min_i(l, r)]; }
int min_i(int l, int r) {
r = min(N, r);
int d = __lg(r - l);
if (A[M[d][r - (1 << d)]] < A[M[d][l]]) return M[d][r - (1 << d)];
else return M[d][l];
}
T max_v(int l, int r) { return A[max_i(l, r)]; }
int max_i(int l, int r) {
r = min(N, r);
int d = __lg(r - l);
if (A[X[d][l]] < A[X[d][r - (1 << d)]]) return X[d][r - (1 << d)];
else return X[d][l];
}
};
//-----------------------------------------------------------------------------------
int N, X[201010], Y[201010];
//-----------------------------------------------------------------------------------
int R[201010], B[201010];
ll solve1() {
rep(i, 0, N) {
R[i] = (min(X[i], Y[i]));
B[i] = (max(X[i], Y[i]));
}
sort(R, R + N);
sort(B, B + N);
return 1LL * (R[N - 1] - R[0]) * (B[N - 1] - B[0]);
}
//-----------------------------------------------------------------------------------
pair<int, int> XY[201010];
ll solve2() {
rep(i, 0, N) XY[i] = { min(X[i], Y[i]), max(X[i], Y[i]) };
sort(XY, XY + N);
vector<int> r, b;
rep(i, 0, N) r.push_back(XY[i].first);
rep(i, 0, N) b.push_back(XY[i].second);
IRMXQ<int> rseg(r);
IRMXQ<int> bseg(b);
ll ans = INF;
rep(i, 1, N) {
int Rmax = max(rseg.max_v(0, i), bseg.max_v(i, N));
int Rmin = min(rseg.min_v(0, i), bseg.min_v(i, N));
int Bmax = max(bseg.max_v(0, i), rseg.max_v(i, N));
int Bmin = min(bseg.min_v(0, i), rseg.min_v(i, N));
ll a = 1LL * (Rmax - Rmin) * (Bmax - Bmin);
ans = min(ans, a);
}
return ans;
}
//-----------------------------------------------------------------------------------
int main() {
cin >> N;
rep(i, 0, N) scanf("%d%d", &X[i], &Y[i]);
cout << min(solve1(), solve2()) << endl;
}
Submission Info
Submission Time |
|
Task |
E - Ball Coloring |
User |
hamayanhamayan |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
3081 Byte |
Status |
AC |
Exec Time |
145 ms |
Memory |
64244 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:87:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i, 0, N) scanf("%d%d", &X[i], &Y[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0, example1, example2 |
All |
div20, div21, div22, div23, div24, example0, example1, example2, maxrand0, maxrand1, maxrand2, maxrand20, maxrand21, maxrand210, maxrand211, maxrand22, maxrand23, maxrand24, maxrand25, maxrand26, maxrand27, maxrand28, maxrand29, maxrand3, maxrand4, smallrand0, smallrand1, smallrand2, smallrand3, smallrand4, sparse0, sparse1, sparse2, sparse3, sparse4 |
Case Name |
Status |
Exec Time |
Memory |
div20 |
AC |
143 ms |
64244 KB |
div21 |
AC |
143 ms |
64244 KB |
div22 |
AC |
145 ms |
64244 KB |
div23 |
AC |
143 ms |
64244 KB |
div24 |
AC |
143 ms |
64244 KB |
example0 |
AC |
2 ms |
2304 KB |
example1 |
AC |
2 ms |
2304 KB |
example2 |
AC |
2 ms |
2304 KB |
maxrand0 |
AC |
144 ms |
64244 KB |
maxrand1 |
AC |
143 ms |
64244 KB |
maxrand2 |
AC |
143 ms |
64244 KB |
maxrand20 |
AC |
135 ms |
64244 KB |
maxrand21 |
AC |
136 ms |
64244 KB |
maxrand210 |
AC |
133 ms |
64244 KB |
maxrand211 |
AC |
135 ms |
64244 KB |
maxrand22 |
AC |
136 ms |
64244 KB |
maxrand23 |
AC |
139 ms |
64244 KB |
maxrand24 |
AC |
144 ms |
64244 KB |
maxrand25 |
AC |
135 ms |
64244 KB |
maxrand26 |
AC |
135 ms |
64244 KB |
maxrand27 |
AC |
138 ms |
64244 KB |
maxrand28 |
AC |
142 ms |
64244 KB |
maxrand29 |
AC |
145 ms |
64244 KB |
maxrand3 |
AC |
144 ms |
64244 KB |
maxrand4 |
AC |
144 ms |
64244 KB |
smallrand0 |
AC |
2 ms |
2304 KB |
smallrand1 |
AC |
2 ms |
2304 KB |
smallrand2 |
AC |
2 ms |
2304 KB |
smallrand3 |
AC |
2 ms |
2304 KB |
smallrand4 |
AC |
2 ms |
2304 KB |
sparse0 |
AC |
128 ms |
64244 KB |
sparse1 |
AC |
127 ms |
64244 KB |
sparse2 |
AC |
127 ms |
64244 KB |
sparse3 |
AC |
127 ms |
64244 KB |
sparse4 |
AC |
128 ms |
64244 KB |