题意:

+ ;
];
;
;
], seg[rt <<  | ]);
)) * fa.setv;
) * fa.setv;
;
], seg[rt <<  | ], r - l + );
;
, R, rson);
;
) * v;
;
], seg[rt <<  | ], r - l + );
, R, v, rson);
], seg[rt <<  | ]);
], seg[rt <<  | ], r - l + );
, R, v, rson);
], seg[rt <<  | ]);
; i <= n; ++i) {
         scanf(                      ar[i] = n + ;
     }
     memset(vis, ,      idx = ;
     build(, n, );
     ll ans = query(, n, , n, );
 
     memset(hap, -,      memset(nex, -,  
     ; i <= n; ++i) {
         )
             hap[ar[i]] = i;
                      nex[hap[ar[i]]] = i;
             hap[ar[i]] = i;
         }
     }
 
          ; i <= n - ; ++i) {
         )
             to = n;
                      to = nex[i] - ;
         update(i, to, ar[i], , n, );
         ans = ans + query(i, n, , n, );
     }
     printf( }
       == scanf(          == n)          work();
     }
     ;
 }

CLJ有一个很诡异的map解法

[2013 ACM/ICPC Asia Regional Hangzhou Online J/1010]hdu 4747 Mex (线段树)-LMLPHP[2013 ACM/ICPC Asia Regional Hangzhou Online J/1010]hdu 4747 Mex (线段树)-LMLPHP
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <cmath>
  typedef  typedef        ;
 
    map< 
  {
     #ifdef __FIO
     freopen(                 ){
                                    ll sum, tsum;
         sum = tsum = ;
         scanf(         )
                      ; i < n; i++){
             scanf(                              a[i] = n+;
         }
         ; i <= n+; i++)
             next[i] = n;
         ; i >= ; i--){
             nextSame[i] = next[a[i]];
             next[a[i]] = i;
         }
         memset(vis, ,          j = ;
         s.clear();
         ; i < n; i++){
             vis[a[i]] =                               j++;
             tsum += j;
             s[i] = j;
         }
         s[n] = n;
         sum += tsum;
         ; i < n-; i++){
             tsum -= s.begin()->se;
             s[i] = -;
             map<);
                                                                        tsum -= (ll)temp*(nextSame[i]-);
                     it--;
                     tsum += (ll)temp*it->fi;
                 }
                                                           tsum -= (ll)temp*it->fi;
                     s.erase(it--);
                     tsum += (ll)temp*it->fi;
                 }
                 s[nextSame[i]-] = a[i];
             }
             s.erase(i);
             sum += tsum;
         }
         printf(     }
     ;
 }
04-15 17:42