Submission #51010

# Submission time Handle Problem Language Result Execution time Memory
51010 2018-06-15T14:55:42 Z tmwilliamlin168 Adriatic (CEOI13_adriatic) C++14
80 / 100
2000 ms 49688 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=2.5e5, mxC=2500;
int n, x[mxN], y[mxN], a[mxC][mxC], pa[mxC+1][mxC+1], uhbx[mxC+1], uhby[mxC+1], lhbx[mxC+1], lhby[mxC+1];

inline int spa(int x1, int y1, int x2, int y2) {
	return pa[x2][y2]-pa[x1][y2]-pa[x2][y1]+pa[x1][y1];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> x[i] >> y[i], --x[i], --y[i];
		a[x[i]][y[i]]=i+1;
		pa[x[i]+1][y[i]+1]=1;
	}
	for(int i=1; i<=mxC; ++i) {
		for(int j=1; j<=mxC; ++j)
			pa[i][j]+=pa[i][j-1];
		for(int j=1; j<=mxC; ++j)
			pa[i][j]+=pa[i-1][j];
		uhbx[i]=uhbx[i-1];
		for(int j=uhbx[i]?y[uhbx[i]-1]-1:mxC-1; j>=0; --j)
			uhbx[i]=a[i-1][j]?a[i-1][j]:uhbx[i];
		uhby[i]=uhby[i-1];
		for(int j=uhby[i]?x[uhby[i]-1]-1:mxC-1; j>=0; --j)
			uhby[i]=a[j][i-1]?a[j][i-1]:uhby[i];
	}
	for(int i=mxC-1; i>=0; --i) {
		lhbx[i]=lhbx[i+1];
		for(int j=lhbx[i]?y[lhbx[i]-1]+1:0; j<mxC; ++j)
			lhbx[i]=a[i][j]?a[i][j]:lhbx[i];
		lhby[i]=lhby[i+1];
		for(int j=lhby[i]?x[lhby[i]-1]+1:0; j<mxC; ++j)
			lhby[i]=a[j][i]?a[j][i]:lhby[i];
	}
	unordered_map<ll, int> hax1;
	for(int i=0; i<n; ++i) {
		int a1=pa[x[i]][y[i]], a2=spa(x[i]+1, y[i]+1, mxC, mxC), ans=-a1-a2-2, d=2, a3;
		if(a1+a2<n-1) {
			int uh1=uhbx[x[i]]-1, uh2=uhby[y[i]]-1, lh1=lhby[y[i]+1]-1, lh2=lhbx[x[i]+1]-1;
			if(!a1)
				uh1=uh2=i;
			if(!a2)
				lh1=lh2=i;
			ll hax2=(((ll)x[uh1]*mxC+x[uh2])*mxC+x[lh1])*mxC+x[lh2];
			//if(hax1.find(hax2)==hax1.end()) {
				while(1) {
					++d;
					a3=pa[x[lh1]][y[lh2]]+spa(x[uh2]+1, y[uh1]+1, mxC, mxC)-spa(x[uh2]+1, y[uh1]+1, x[lh1], y[lh2]);
					ans-=a3;
					if(a3>=n)
						break;
					int nuh1=uhbx[x[lh1]]-1, nuh2=uhby[y[lh2]]-1;
					lh1=lhby[y[uh1]+1]-1, lh2=lhbx[x[uh2]+1]-1, uh1=nuh1, uh2=nuh2;
				}
				hax1[hax2]=ans+a1+a2+2+(d-2)*n;
			//} else
			//	ans+=hax1[hax2];
		}
		cout << ans+d*n << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 25208 KB Output is correct
2 Correct 44 ms 25316 KB Output is correct
3 Correct 71 ms 25352 KB Output is correct
4 Correct 87 ms 25428 KB Output is correct
5 Correct 70 ms 25428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 29592 KB Output is correct
2 Correct 46 ms 30396 KB Output is correct
3 Correct 81 ms 30396 KB Output is correct
4 Correct 87 ms 30396 KB Output is correct
5 Correct 68 ms 30396 KB Output is correct
6 Correct 94 ms 30396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 33708 KB Output is correct
2 Correct 53 ms 38940 KB Output is correct
3 Correct 102 ms 38940 KB Output is correct
4 Correct 94 ms 38940 KB Output is correct
5 Correct 71 ms 38940 KB Output is correct
6 Correct 385 ms 38940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 717 ms 38940 KB Output is correct
2 Correct 72 ms 49688 KB Output is correct
3 Correct 132 ms 49688 KB Output is correct
4 Correct 95 ms 49688 KB Output is correct
5 Correct 90 ms 49688 KB Output is correct
6 Correct 1779 ms 49688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2064 ms 49688 KB Time limit exceeded
2 Halted 0 ms 0 KB -