#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=10;
int n,t,a[N],b[N],id[N][N],cnt[N][N],dp[N][N],pd[N][N];
pair<int,int> A[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]);
//cout<<i<<" "<<j<<" "<<x<<" "<<y<<endl;
pd[i][j]=get(1,j,i,m)+pd[x][y];
}
}
//eror(pd[6][1]);
}
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:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
96 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
9936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
17880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
23544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
431 ms |
32592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |