fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define rep(i, n) for (int i = 0; i < (n); ++i)
  5.  
  6. template<class Monoid>
  7. class SegTree {
  8. private:
  9. using T = typename Monoid::T;
  10. Monoid op;
  11. const int n;
  12. vector<T> t;
  13.  
  14. void prop_to(int i) { t[i] = op(t[2*i], t[2*i+1]); }
  15.  
  16. public:
  17. SegTree(int n) : n(n), t(2*n, op.identity()) {}
  18. SegTree(const vector<T>& v) : n(v.size()), t(2*n) {
  19. copy(begin(v), end(v), begin(t) + n);
  20. for (int i = n-1; i > 0; --i) prop_to(i);
  21. }
  22.  
  23. void set(int i, const T& x) {
  24. t[i += n] = x;
  25. while (i >>= 1) prop_to(i);
  26. }
  27.  
  28. T get(int i) { return t[i + n]; }
  29.  
  30. T accumulate(int l, int r) {
  31. T accl = op.identity(), accr = op.identity();
  32. for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
  33. if (l & 1) accl = op(accl, t[l++]);
  34. if (r & 1) accr = op(t[r-1], accr);
  35. }
  36. return op(accl, accr);
  37. }
  38. };
  39.  
  40. struct RMQ {
  41. using T = int;
  42. T operator()(const T& a, const T& b) { return a < b ? a : b; }
  43. static constexpr T identity() { return INT_MAX; }
  44. };
  45.  
  46. int main() {
  47. int n = 1e7;
  48. vector<int> a(n);
  49. rep(i, n) a[i] = i;
  50. SegTree<RMQ> rmq(a);
  51. bool f = true;
  52. rep(i, n) {
  53. int l = rand()%n, r = rand()%n;
  54. if (l == r) continue;
  55. if (l > r) swap(l, r);
  56. f &= rmq.accumulate(l, r) == l;
  57. }
  58. cout << (f ? "OK" : "NG") << endl;
  59. }
  60.  
Success #stdin #stdout 2.08s 3468KB
stdin
Standard input is empty
stdout
OK