Submission #531661

# Submission time Handle Problem Language Result Execution time Memory
531661 2022-03-01T08:28:57 Z Koosha_mv Adriatic (CEOI13_adriatic) C++14
100 / 100
594 ms 203900 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=2525,m=2505;

int n,t,a[N],b[N],id[N][N],cnt[N][N],dp[N][N],pd[N][N];
pair<int,int> A[N*N];

int get(int sx,int sy,int tx,int ty){
	sx--,sy--;
	return cnt[tx][ty]-cnt[sx][ty]-cnt[tx][sy]+cnt[sx][sy];
}
void build(){
	f(i,1,m+1){
		f(j,1,m+1){
			cnt[i][j]+=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1];
		}
	}
}
void solvedp(){
	a[0]=N;
	f(i,1,m+1){
		a[i]=a[i-1];
		f(j,1,m+1){
			if(id[i][j]){
				minm(a[i],j);
			}
		}
	}
	b[m+1]=0;
	f_(i,m,1){
		b[i]=b[i+1];
		f(j,1,m+1){
			if(id[j][i]){
				maxm(b[i],j);
			}
		}
	}
	f_(i,m,1){
		f(j,1,m+1){
			int x=max(i,b[j+1]),y=min(j,a[i-1]);
			dp[i][j]=get(i,1,m,j)+dp[x][y];
		}
	}
}
void solvepd(){
	a[m+1]=0;
	f_(i,m,1){
		a[i]=a[i+1];
		f(j,1,m+1){
			if(id[i][j]){
				maxm(a[i],j);
			}
		}
	}
	b[0]=m+1;
	f(i,1,m+1){
		b[i]=b[i-1];
		f(j,1,m+1){
			if(id[j][i]){
				minm(b[i],j);
			}
		}
	}
	f(i,1,m+1){
		f_(j,m,1){
			int x=min(i,b[j-1]),y=max(j,a[i+1]);
			pd[i][j]=get(1,j,i,m)+pd[x][y];
		}
	}
}


main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n;
	f(i,1,n+1){
		int x,y;
		cin>>x>>y;
		A[i]={x,y};
		id[x][y]=i;
		cnt[x][y]++;
	}
	build();
	solvedp();
	solvepd();
	f(i,1,n+1){
		int x=A[i].F,y=A[i].S;
		cout<<dp[x][y]+pd[x][y]+n-3<<endl;
	}
}

Compilation message

adriatic.cpp:94:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   94 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 197 ms 149324 KB Output is correct
2 Correct 212 ms 149312 KB Output is correct
3 Correct 194 ms 149440 KB Output is correct
4 Correct 194 ms 148984 KB Output is correct
5 Correct 200 ms 149384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 153472 KB Output is correct
2 Correct 210 ms 154548 KB Output is correct
3 Correct 201 ms 153560 KB Output is correct
4 Correct 200 ms 149432 KB Output is correct
5 Correct 195 ms 149732 KB Output is correct
6 Correct 204 ms 151620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 157568 KB Output is correct
2 Correct 210 ms 165448 KB Output is correct
3 Correct 207 ms 157980 KB Output is correct
4 Correct 204 ms 150888 KB Output is correct
5 Correct 201 ms 150244 KB Output is correct
6 Correct 256 ms 159168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 269 ms 160508 KB Output is correct
2 Correct 277 ms 192140 KB Output is correct
3 Correct 244 ms 161108 KB Output is correct
4 Correct 233 ms 153312 KB Output is correct
5 Correct 239 ms 152004 KB Output is correct
6 Correct 277 ms 160368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 166936 KB Output is correct
2 Correct 594 ms 203900 KB Output is correct
3 Correct 585 ms 182708 KB Output is correct
4 Correct 573 ms 166576 KB Output is correct
5 Correct 542 ms 160484 KB Output is correct
6 Correct 573 ms 169848 KB Output is correct
7 Correct 574 ms 168876 KB Output is correct