More than 2019 cattle off summer school camp (seventh) E + segment tree discrete intervals

The meaning of problems

Each insertion interval \ ([L_i, R_i] \ ) number between query median.

analysis

Into the range of discrete points, you can use the tree line to support the update and query.

We will right the interval +1 point, the length of the interval is a right end point minus the left point, then we will look at all endpoints with discrete segment tree maintenance on the line.

For example the interval \ ([1,2], [2,4] \)

+1 becomes the right end of the interval \ ([1,3), [2,5) \)

After discrete \ (1,2,3,4 \)

\ (1 \) representative of the interval \ ([1,2) \) , \ (2 \) representative of the interval \ ([2,3) \) , \ (3 \) representative of the interval \ ([3,5) \) , \ (4 \) does not represent any range.

  • Update interval \ ([l, r) \ ) when (r + 1 plus the right end point), since the point \ (r-1 \) section is represented by \ ([R & lt-. 1, R & lt) \) , we update interval \ ([l, r-1 ] \) of points on it.
  • Find the point where the median interval from a tree half a query, and then calculate the interval in which the number is on the line.

Code

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=8e5+10;
const int N=1e9;
int n,m;
ll X1,X2,A1,B1,C1,M1,Y1,Y2,A2,B2,C2,M2;
int L[maxn],R[maxn],b[maxn];
ll a[maxn<<2],tag[maxn<<2];
void up(int dl,int dr,int l,int r,int p){
    a[p]+=b[dr+1]-b[dl];
    if(l==dl&&r==dr) return tag[p]++,void();
    int mid=l+r>>1;
    if(dr<=mid) up(dl,dr,lson);
    else if(dl>mid) up(dl,dr,rson);
    else up(dl,mid,lson),up(mid+1,dr,rson);
}
int qy(int l,int r,int p,ll x,ll k){
    if(l==r){
        ll g=a[p]/(b[l+1]-b[l])+k;
        return b[l]+(x+g-1)/g-1;
    }
    int mid=l+r>>1;
    ll res=a[p<<1]+(k+tag[p])*(b[mid+1]-b[l]);
    if(x<=res) return qy(lson,x,k+tag[p]);
    else return qy(rson,x-res,k+tag[p]);
}
int main(){
    //ios::sync_with_stdio(false);
    //freopen("in","r",stdin);
    scanf("%d",&n);
    cin>>X1>>X2>>A1>>B1>>C1>>M1;
    cin>>Y1>>Y2>>A2>>B2>>C2>>M2;
    ll X=X1,Y=Y1,K=0;
    for(int i=1;i<=min(n,2);i++){
        if(i==2) X=X2,Y=Y2;
        L[i]=min(X,Y)+1,R[i]=max(X,Y)+1;
        b[++m]=L[i];b[++m]=R[i]+1;
    }
    for(int i=3;i<=n;i++){
        X=(A1*X2%M1+B1*X1%M1+C1)%M1;
        Y=(A2*Y2%M2+B2*Y1%M2+C2)%M2;
        L[i]=min(X,Y)+1,R[i]=max(X,Y)+1;
        b[++m]=L[i];b[++m]=R[i]+1;
        X1=X2;X2=X;
        Y1=Y2;Y2=Y;
    }
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n;i++){
        L[i]=lower_bound(b+1,b+m+1,L[i])-b;
        R[i]=lower_bound(b+1,b+m+1,R[i]+1)-b;
        K+=b[R[i]]-b[L[i]];
        up(L[i],R[i]-1,1,m,1);
        printf("%d\n",qy(1,m,1,(K+1)/2,0));
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/xyq0220/p/12093453.html