EntropyIncreaser

sone1

May 31st, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. // http://darkbzoj.tk/problem/3153
  2.  
  3. #include <cstdio>
  4.  
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int INF = 1 << 29;
  10. const bool rake = false, compress = true;
  11.  
  12. struct Value {
  13.   int sz, sum, max;
  14.  
  15.   Value(int sz = 0, int sum = 0, int max = -INF) : sz(sz), sum(sum), max(max) {}
  16. };
  17.  
  18. struct Tag {
  19.   int k, b;
  20.  
  21.   Tag(int k = 1, int b = 0) : k(k), b(b) {}
  22.  
  23.   int operator()(int x) const { return k * x + b; }
  24.  
  25.   operator bool() const { return k != 1 || b != 0; }
  26. };
  27.  
  28. Value merge(const Value& lhs, const Value& rhs) {
  29.   return Value(lhs.sum + rhs.sum, max(lhs.max, rhs.max));
  30. }
  31.  
  32. Value effort(const Tag& op, const Value& v) {
  33.   return Value(v.sz, v.sum * op.k + v.sz * op.b, op(v.max));
  34. }
  35.  
  36. Tag composite(const Tag& lhs, const Tag& rhs) {
  37.   return Tag(lhs.k * rhs.k, lhs(rhs.b));
  38. }
  39.  
  40. struct Node {
  41.   union {
  42.     struct { Node *ls, *rs, *vs; };
  43.     Node* ch[3];
  44.   };
  45.  
  46.   Node* prt;
  47.   Value v, value[2];
  48.   Tag tag[2];
  49.  
  50.   int relation() const { return find(prt->ch, prt->ch + 3, const_cast<Node*>(this)) - prt->ch; }
  51.  
  52.   template <bool t> void update();
  53.   template <bool t> void pushDown();
  54.   template <bool t> void change(const Tag& tag);
  55. };
  56.  
  57. template <bool t> Value get(const Node* o) {
  58.   return o ? effort(o->tag[t], o->value[t]) : Value();
  59. }
  60.  
  61. template <> void Node::update<rake>() {
  62.   value[rake] = merge(merge(get<rake>(ls), v), merge(get<rake>(rs), get<rake>(vs)));
  63. }
  64.  
  65. template <> void Node::update<compress>() {
  66.   value[compress] = merge(merge(get<compress>(ls), v), get<compress>(rs));
  67. }
  68.  
  69. template<> void Node::pushDown<rake>() {
  70.   if (tag[rake]) {
  71.    
  72.     tag[rake] = Tag();
  73.   }
  74. }
  75.  
  76. const int N = 100010;
  77.  
  78.  
  79. int main() {
  80.   return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment