2827: Birds of a Thousand Mountains Fly is not a treap

The topic of international practice:

It looks like it is impossible to do, let's sort out the meaning of the topic first.
That is, maintain the two largest attribute values ​​that each point has ever had, and support moving the position of the point.
We discretize each position with a map and build a balanced tree for each position. To facilitate separation, the key to this balanced tree is the node number.
Then treat each point as a node and put it into the balanced tree at its location.
All that's left to do is to balance the tree to separate out a point, merge a point, and mark it.
For the marking of morale value, we maintain the max in the balanced tree. When merging, use the might value of this new point to mark the entire tree, and then use the max in the tree to mark this new point.
The mark of unity value, just play together after merging. In addition, in fact, we don't need to maintain the size on the balanced tree, just open a map to maintain it.
In the final query, in order to let all the markers go down, we can forcefully remove each point.
The non-rotating treap constant is slightly larger (maybe my posture is not very correct QAQ)

code:

  1 #pragma GCC optimize(2)
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<map>
  6 #include<cctype>
  7 typedef long long int lli;
  8 const int maxn=5e5+1e2;
  9 
 10 struct Point {
 11     int x,y;
 12     friend bool operator < (const Point &a,const Point &b) {
 13         return a.x != b.x ? a.x < b.x : a.y < b.y;
 14     }
 15 };
 16 
 17 std::map<int,int> siz;
 18 int w[maxn],hsw[maxn],hss[maxn],fix[maxn],bel[maxn];
 19 int lson[maxn],rson[maxn],lazyw[maxn],lazys[maxn],mxw[maxn];
 20 int root[maxn];
 21 
 22 typedef std::pair<int,int> pii;
 23 __inline pii mp(const int &x,const int &y) { return std::make_pair(x,y); }
 24 
 25 inline void maintain(int pos) {
 26     mxw[pos] = std::max( std::max(mxw[lson[pos]],mxw[rson[pos]]) , w[pos] );
 27 }
 28 inline void applyw(int pos,const int &ww) {
 29     if( !pos ) return;
 30     lazyw[pos] = std::max( lazyw[pos] , ww ) , hsw[pos] = std::max( hsw[pos] , ww );
 31 }
 32 inline void applys(int pos,const int &ss) {
 33     if( !pos ) return;
 34     lazys[pos] = std::max( lazys[pos] , ss ) , hss[pos] = std::max( hss[pos] , ss );
 35 }
 36 inline void push(int pos) {
 37     if( lazyw[pos] ) applyw(lson[pos],lazyw[pos]) , applyw(rson[pos],lazyw[pos]) , lazyw[pos] = 0;
 38     if( lazys[pos] ) applys(lson[pos],lazys[pos]) , applys(rson[pos],lazys[pos]) , lazys[pos] = 0;
 39 }
 40 inline pii split(int pos,int tar) { // split first tar nodes into left .
 41     if( !pos ) return mp(0,0);
 42     push(pos);
 43     if( tar < pos ) { // split left .
 44         pii spl = split(lson[pos],tar);
 45         lson[pos] = spl.second , maintain(pos);
 46         return mp(spl.first,pos);
 47     } else {
 48         pii spr = split(rson[pos],tar);
 49         rson[pos] = spr.first , maintain(pos);
 50         return mp(pos,spr.second);
 51     }
 52 }
 53 inline int merge(int x,int y) {
 54     if( x == y || !x || !y ) return x | y;
 55     push(x) , push(y);
 56     if( x > y ) std::swap(x,y);
 57     if( fix[x] < fix[y] ) { // x will be the father .
 58         rson[x] = merge(rson[x],y) , maintain(x);
 59         return x;
 60     } else {
 61         lson[y] = merge(x,lson[y]) , maintain(y);
 62         return y;
 63     }
 64 }
 65 
 66 inline void remove(int x) { // split x from it's tree into a single node .
 67     pii spr = split(root[bel[x]],x) , spl = split(spr.first,x-1);
 68     root[bel[x]] = merge(spl.first,spr.second) , --siz[bel[x]];
 69 }
 70 inline void insert(int x,int id) { // insert x into root[id] .
 71     applyw(root[id],w[x]) , applyw(x,mxw[root[id]]);
 72     pii sp = split(root[id],x);
 73     root[id] = merge(merge(sp.first,x),sp.second) , applys(root[id],siz[id]++);
 74 }
 75 
 76 inline int getpos(const Point &p) {
 77     static std::map<Point,int> cov;
 78     static int cnt = 0;
 79     if( cov.find(p) == cov.end() ) return cov[p] = ++cnt;
 80     else return cov[p];
 81 }
 82 
 83 inline char nextchar() {
 84     static const int BS = 1 << 21;
 85     static char buf[BS],*st=buf+BS,*ed=st;
 86     if( st == ed ) ed = buf + fread(st=buf,1,BS,stdin);
 87     return st == ed ? -1 : *st++;
 88 }
 89 inline int getint() {
 90     int ret = 0 , fix = 1 , ch;
 91     while( !isdigit(ch=nextchar()) ) fix = ch == '-' ? -fix : fix;
 92     do ret=ret*10+ch-'0'; while( isdigit(ch=nextchar()) );
 93     return ret * fix;
 94 }
 95 
 96 int main() {
 97     static int n,t;
 98     n = getint();
 99     for(int i=1,x,y;i<=n;i++) mxw[i] = w[i] = getint() , x = getint() , y = getint() , insert(i,bel[i]=getpos((Point){x,y})) , fix[i] = i;
100     t = getint() , std::random_shuffle(fix+1,fix+1+n);
101     for(int i=1,p,x,y;i<=t;i++) p = getint() , x = getint() , y = getint() , remove(p) , insert(p,bel[p]=getpos((Point){x,y}));
102     for(int i=1;i<=n;i++) remove(i);
103     for(int i=1;i<=n;i++) printf("%lld\n",(lli)hss[i]*hsw[i]);
104     return 0;
105 }
View Code



Even if it doesn't reach you even if it's far away, it 's an
immediate use . Ya Noh , who is becoming a smile, is released . Lol essay one small and small lie I 'm swaying in the wind, but I'm still in the middle of my life














Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326620227&siteId=291194637