2827: 千山鸟飞绝 非旋treap

国际惯例的题面:

看起来很不可做的样子,我们先来整理一下题意吧。
就是,维护每个点曾经拥有过的最大的两个属性值,支持把点的位置移动。
我们用map对每个位置进行离散化,对每个位置建立一个平衡树。为了方便分离,这个平衡树的关键字是节点编号。
然后把每个点当做一个节点,放进其所在位置的平衡树里。
剩下要做的就是平衡树分离出一个点,合并一个点,还有打标记了。
对于士气值的标记,我们维护平衡树中的max,每次合并的时候,用这个新点的威武值去给整棵树打标记,再用树中的max给这个新点打标记。
团结值的标记,合并后一起打就好了。另外其实我们不需要在平衡树上维护size的,再开个map维护下就好了。
最后查询的时候,为了让标记全部下放,我们强行把每个点都拆出来就行了。
非旋treap常数略大(可能我的姿势不是很正确QAQ)

代码:

  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



遠くても 届かなくても
即使已经远逝 已经无法传达
今宵、確かな夢を刻む
今宵、仍然能刻画出一个真切的梦
始まりの朝 一人ぼっち同士の誰かも
在新的早晨 让那些同样独身的沦落人
笑顔になってゆく
也能逐渐绽放出笑颜

カタチ取る この胸の中
将这情景在心中幻化成形
ずっと、いつでも描けるよう
一直、无论何时都能描绘出来
ささやかな嘘 さみしくないよ、なんて 微笑った
微微笑着说出一个小小的谎言 我并不寂寞哦
風に 揺れるけど
在风中 依旧不变的摇曳着

posted @ 2018-05-09 21:15  Cmd2001  阅读(268)  评论(0编辑  收藏  举报