ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

珂朵莉树合集

2022-08-20 11:34:33  阅读:148  来源: 互联网

标签:int split 朵莉树 cht mp res 合集 first


Color the Ball

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

//conllexpr int mod = 998244353;
//conllexpr int mod = 1000000007;

template <typename T> 
class ChthollyTree {
 public:
  map<int, T> mp;
  ChthollyTree() { mp[0] = 0; }
  inline void split(int x) {
    auto it = prev(mp.upper_bound(x));
    mp[x] = it->second;
  }
  inline T assign(int l, int r, T x) {
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    while (it->first != r + 1) {
      it->second = x;
      it = mp.erase(it);
    }
    mp[l] = x;
  }
};

void solve() {
  int n;
  while (cin >> n) {
    ChthollyTree<int> cht;
    for (int i = 0; i < n; i++) {
      int l, r;
      cin >> l >> r;
      char ch;
      cin >> ch;
      int color = 0;
      if (ch == 'w') {
        color = 1;
      } else {
        color = 0;
      }
      cht.assign(l, r, color);
    }
    bool ok = 0;
    int len = -1;
    int ll = 0, rr = 0;
    int mxl = 0, mxr = 0;
    for (auto it = cht.mp.begin(); it != cht.mp.end(); it++) {
      if (it->second == 1 && ok == 0) {
        ll = it->first;
        rr = next(it)->first - 1;
        ok = 1;
      } else if (it->second == 0 && ok == 1) {
        rr = it->first - 1;
        ok = 0;
        if (len < rr - ll + 1) {
          mxl = ll;
          mxr = rr;
          len = rr - ll + 1;
        }
      }
    }
    if (len < rr - ll + 1) {
      mxl = ll;
      mxr = rr;
      len = rr - ll + 1;
    }
    if (len == -1) {
      cout << "Oh, my god" << '\n';
    } else {
      cout << mxl << " " << mxr << '\n';
    }
  }
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout << setprecision(6);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

Physical Education Lessons

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

//constexpr int mod = 998244353;
//constexpr int mod = 1000000007;

template <typename T> 
class ChthollyTree {
 public:
  map<int, T> mp;
  ChthollyTree() { mp[0] = 0; }
  inline void split(int x) {
    auto it = prev(mp.upper_bound(x));
    mp[x] = it->second;
  }
  inline T get(int l, int r, T x) {
    T res = 0;
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    while (it->first != r + 1) {
      res -= it->second * (next(it)->first - it->first);
      it = mp.erase(it);
    }
    mp[l] = x;
    res += x * (r - l + 1);
    return res;
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  ChthollyTree<int> cht;
  cht.mp[1] = 1;
  cht.mp[n + 1] = 0;
  int ans = n;
  for (int i = 0; i < q; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    ans += cht.get(l, r, k - 1);
    cout << ans << '\n';
  }
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

Willem, Chtholly and Seniorious

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

//constexpr int mod = 998244353;
constexpr int mod = 1000000007;

template<typename T, typename U>
inline T POW(T a, U b, int p) {
  T res = 1;
  a %= p;
  while (b) {
    if (b & 1) res = res * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return res;
}

template<typename T>
class Chthollytree {
 public:
  map<int, T> mp;
  Chthollytree() { mp[0] = 0; }
  inline void split(int x) {
    auto it = prev(mp.upper_bound(x));
    mp[x] = it->second;
  }
  inline void assign(int l, int r, T x) {
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    while (it->first != r + 1) {
      it = mp.erase(it);
    }
    mp[l] = x;
  }  
  inline void add(int l, int r, T x) {
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    while (it->first != r + 1) {
      it->second += x;
      it = next(it);
    }
  }
  inline T get(int l, int r, int x, int y) {
    i64 res = 0;
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    while (it->first != r + 1) {
      res = (res + POW(it->second, x, y) * (next(it)->first - it->first) % y) % y;
      it = next(it);
    }
    return res;
  }
  inline T nth_element(int l, int r, int k) {
    split(l);
    split(r + 1);
    auto it = mp.find(l);
    vector<pair<T, T>> a;
    while (it->first != r + 1) {
      a.push_back({it->second, next(it)->first - it->first});
      it = next(it);
    }
    sort(a.begin(), a.end());
    for (int i = 0, cnt = 0; ; i++) {
      if (k <= (cnt += a[i].second)) {
        return a[i].first;
      }
    }
  }
};

void solve() {
  int n, m, seed, vmax;
  auto rnd = [&]() {
    int ret = seed;
    seed = (seed * 7LL + 13) % mod;
    return ret;    
  };
  cin >> n >> m >> seed >> vmax;
  Chthollytree<i64> cht;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = (rnd() % vmax) + 1;
    cht.mp[i] = a[i];
  }
  for (int i = 1; i <= m; ++i) {
    int op, l, r, x, y;
    op = (rnd() % 4) + 1;
    l = (rnd() % n);
    r = (rnd() % n);
    if (l > r) {
      swap(l, r);
    }
    if (op == 3) {
      x = (rnd() % (r - l + 1)) + 1;
    } else {
      x = (rnd() % vmax) + 1;
    }
    if (op == 4) {
      y = (rnd() % vmax) + 1;
    }
    if (op == 1) {
      cht.add(l, r, x);
    } else if (op == 2) {    
      cht.assign(l, r, x);
    } else if (op == 3) {
      cout << cht.nth_element(l, r, x) << '\n';
    } else {
      cout << cht.get(l, r, x, y) << '\n';
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

标签:int,split,朵莉树,cht,mp,res,合集,first
来源: https://www.cnblogs.com/kiddingma/p/16607367.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有