2019ICPC Nanjing Network Game A The beautiful values of the palace

Meaning of the questions: Snake fill a large number of versions, some values ​​need to find the number of bits of the given coordinates and then ask q times, a rectangular area is the number and value of

Problem-solving ideas: two-dimensional partial order of prefixes and classic title

Two-dimensional partial order: find (x, y) of the number of the lower left corner, the idea is x, y ascending order, maintenance times each y ordinate array has occurred in a tree, we will dynamically longitudinal point y coordinates to join Fenwick tree, then y is smaller than the calculated how many (Fenwick tree sum) of two-dimensional partial order to know the value of the current point

Prefix and requirements, we only need to maintain the number of points can be changed to the right point.

The problem, according to the laws of the number of first serpentine fill find the right point, then that is seeking a two-dimensional partial order and the prefix, with the prefix and we will be able to quickly get the sub-region and the matrix (matrix Lenovo O (1) query the method of sub-matrices), first we want to ask offline, and then point to involve all into an array after sorting, storage time point can take some tips rectangular boundary marked with weights and point requirements, when when dealing with a right to the point, we joined stumps array processing to the rectangular boundary points, and prefix query once, and then counted ans [id], id is the point in time of the inquiry, the ordinate y of this problem is within 1e6, therefore no need discrete, directly open Fenwick tree 1e6 is the best choice, topic specific details, see the code and comments

AC (Bu Ti) Code:

#include <bits / STDC ++ H.>
 the using  namespace STD;
 const  int MAXN = 1e6 + . 5 ; 
typedef Long  Long LL;
 struct Node 
{ 
    int X, Y, Val, ID; 
    Friend BOOL  operator <( const Node & A, const Node & B ) 
    { 
        IF (AX = BX)! return AX < BX;
         IF (by AY =)! return AY < by;
         return a.id <b.id; // ensure the required value and the first addition point, and then added a rectangular boundary point, boundary point number with a query sequence with the value of the point id = 0
    } 
} P [Maxn]; 
int n;
int getval ( int x, int y) 
{ 
    x = n + 1 - x; 
    and = n + 1 - y; 
    ll ans; 
    ll mi = min (x, min (y, min (n-x + 1 , n-y + 1 )));
    if (x <= y) ans = 1LL * mi * (1LL * 4 * (n- 1 ) - 4 * my) + 1LL * 10 * mi- 4 * n 3 + x + y;
    else ans = 1LL * my * ( 4 * n- 4mi The *) + 1LL * 2 * mi The + . 1 -XY; // simulation 
    int TOT = 0 ;
     the while (ANS) 
    { 
        TOT + ANS% = 10 ; 
        ANS / = 10 ; 
    } 
    return TOT; 
} 
int Tree [MAXN]; // 1e6 without discrete 
inline int lowbit ( int X) { return X & - X;}
 void the Add ( int POS, int Val) 
{ 
    the while (POS <= n-) 
    {
        tree[pos]+=val;
        pos+=lowbit(pos);
    }
}
ll query(int pos)
{
    ll res=0;
    while (pos>0)
    {
        res+=tree[pos];
        pos-=lowbit(pos);
    }
    return res;
}
ll ans[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T,m,q,x1,y1,x2,y2;
    cin>>T;
    while (T--)
    {
        cin>>n>>m>>q;
        memset(tree,0, sizeof(tree));
        for(int i=1;i<=m;i++)
        {
            cin>>p[i].x>>p[i].y;
            p[i].val=getval(p[i].x,p[i].y);
            p[i].id=0;
        }
        int len=m;
        for(inti =
        }1 ; i <= q; j ++ ) 
        { 
            ans [i] = 0 ; 
            cin >> x1 y1 >> >> >> x2 y2; 
            p [ ++ only] .x = X @ 1 1 , P [as] .y = Y 1 1 , P [as] .id = i, P [as] .val = 1 ; 
            p [ ++ only] .x = X 2, P [as] .y = Y 2, P [as] .id = i, P [as] .val = 1 ; 
            p [ ++ only] .x = X @ 1 1 , P [as] .y = Y 2, P [as] .id = i, P [as] .val = - 1 ; 
            p [ ++ only] .x = X 2, P [as] .y = Y 1 1 , P [as] .id = i, P [as] .val = - 1 ; 
        sort (P + 1 , P + len + . 1 ); 

        for ( int I = . 1 ; I <= len; I ++ ) 
        { 
            IF (P [I] .id) // If rectangular boundary points is calculated answer 
            { 
                ANS [P [ I] .id] + = Query 1LL * (P [I] .y) * P [I] .val; // rectangular boundary point meaning val is labeled ans [id] is the current prefix and the plus or minus the current and prefix 
            }
             the else the Add (P [I] .y, P [I] .val); 
        } 
        for ( int I = . 1 ; I <= Q; I ++) COUT << ANS [I] << ' \ n- ' ; 
    } 
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/xusirui/p/11448642.html