A Dyson Sphere is a hypothetical megastructure that completely encompasses a star and captures a large percentage of its power output. The concept is a thought experiment that attempts to explain how a spacefaring civilization would meet its energy requirements once those requirements exceed what can be generated from the home planet's resources alone. Only a tiny fraction of a star's energy emissions reach the surface of any orbiting planet. Building structures encircling a star would enable a civilization to harvest far more energy.
One day, Moca has another idea for a thought experiment. Assume there is a special box called Dyson Box. The gravitational field in this box is unstable. The direction of the gravity inside the box can not be determined until it is opened.
The inside of the box can be formed as a 222-dimensional grid, while the bottom left corner's coordinate is (0,0)(0, 0)(0,0) and the upper right corner's coordinate is (2⋅105,2⋅105)(2 \cdot 10^5, 2 \cdot 10^5)(2⋅105,2⋅105). There will be nnn events. In the iii-th event, a new cube will appear, whose upper right corner's coordinate is (xi,yi)(x_i, y_i)(xi,yi) and bottom left corner's coordinate is (xi−1,yi−1)(x_i - 1, y_i - 1)(xi−1,yi−1).
There are two directions of gravity in the box, vertical and horizontal. Suppose Moca opens the box after the iii-th event. In that case, she has 12\frac{1}{2}21 probability of seeing the direction of the gravity inside the box is vertical, and the other 12\frac{1}{2}21 probability is horizontal. And then, she will measure the total length of the outline of all the cubes. If the direction of gravity is horizontal, all the cubes inside will move horizontally to the left under its influence. Similarly, vertical gravity will cause all the cubes to move downward.
Moca hates probability, so that she is asking for your help. If you have known the coordinates of all the cubes in chronological order, can you calculate the total length of these two cases after each event?
输入描述:
The first line contains one integer nnn (1≤n≤2⋅105)(1 \le n \le 2 \cdot 10^5)(1≤n≤2⋅105) -- the number of cubes.
Each of the following nnn lines describes a cube with two integers xi,yix_i, y_ixi,yi (1≤xi,yi≤2⋅105)(1 \le x_i, y_i \le 2 \cdot 10^5)(1≤xi,yi≤2⋅105).
It is guaranteed that no two cubes have the same coordinates.
输出描述:
For each of the nnn cubes, print one line containing two integers -- two answers when the the direction of gravity is vertical and horizontal.
示例1
输入
4 1 2 3 2 2 1 4 1
输出
4 4 8 6 8 8 10 8
模拟一下
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define endl '\n'
#define lowbit(x) ((x)&-(x))
const int N=2e6+10;
const int mod =998244353;
typedef long long ll;
ll ans=0,n1,m1;
ll t=0,s1=0,s2=0,s3=0,s4=0,max1=0,max2=0,min1=100000000,sum=0,n,m,i,j,k,r,l;
inline int read() {
bool sym=0;
int res=0;
char ch=getchar();
while(!isdigit(ch))sym |=(ch =='-'),ch=getchar();
while(isdigit(ch)) res =(res<<3)+(res<<1)+(ch^48),ch=getchar();
return sym ? -res : res;
}
void print(int x) {
if(!x)return;
print(x/10);
putchar(x%10+'0');
}
int isPrime(int n) {
float n_sqrt;
if(n==1) return 0;
if(n==2 || n==3) return 1;
if(n%6!=1 && n%6!=5) return 0;
n_sqrt=floor(sqrt((float)n));
for(int i=5; i<=n_sqrt; i+=6) {
if(n%(i)==0 | n%(i+2)==0) return 0;
}
return 1;
}
ll a[200086],b[200005],a1[200005],a2[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
a1[a[i]]++;
ll aa=4;
if(a1[a[i]]!=1)
aa-=2;
if(a1[a[i]-1]>=a1[a[i]])
aa-=2;
if(a1[a[i]+1]>=a1[a[i]])
aa-=2;
s1+=aa;
cout<<s1;
a2[b[i]]++;
ll bb=4;
if(a2[b[i]]!=1)
bb-=2;
if(a2[b[i]-1]>=a2[b[i]])
bb-=2;
if(a2[b[i]+1]>=a2[b[i]])
bb-=2;
/*if(a2[b[i]+1]==a2[b[i]])
bb-=2;*/
s2+=bb;
cout<<" "<<s2<<endl;
}
return 0;
}
//mio lover