답안 #1031276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031276 2024-07-22T16:39:28 Z evenvalue Watering can (POI13_kon) C++17
100 / 100
205 ms 22160 KB
#include "koninc.h"
#include <bits/stdc++.h>
using namespace std;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

using int64 = long long;
using ld = long double;

constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;

struct node {
  int mini = kInf;
  int lazy = 0;
  int mature = 0;
};

class SegTree {
  int n;
  vector<node> t;

  static node unite(const node &l, const node &r) {
    node ans;
    ans.mini = min(l.mini, r.mini);
    ans.mature = l.mature + r.mature;
    return ans;
  }

  void push(const int x, const int l, const int r) {
    if (t[x].lazy == 0) return;
    const int mid = (l + r) / 2;
    const int y = 2 * (mid - l + 1) + x;
    for (const int child : {x + 1, y}) {
      t[child].mini -= t[x].lazy;
      t[child].lazy += t[x].lazy;
    }
    t[x].lazy = 0;
  }

  void build(const int x, const int l, const int r, const vector<node> &a) {
    if (l == r) {
      t[x] = a[l];
      return;
    }
    const int mid = (l + r) / 2;
    const int y = 2 * (mid - l + 1) + x;
    build(x + 1, l, mid, a);
    build(y, mid + 1, r, a);
    t[x] = unite(t[x + 1], t[y]);
  }

  void decrease(const int x, const int l, const int r, const int ql, const int qr) {
    if (ql <= l and r <= qr and t[x].mini > 1) {
      t[x].mini--;
      t[x].lazy++;
      return;
    }
    if (l == r) {
      t[x].mini = kInf;
      t[x].lazy = 0;
      t[x].mature = 1;
      return;
    }
    push(x, l, r);
    const int mid = (l + r) / 2;
    const int y = 2 * (mid - l + 1) + x;
    if (ql <= mid) {
      decrease(x + 1, l, mid, ql, qr);
    }
    if (mid < qr) {
      decrease(y, mid + 1, r, ql, qr);
    }
    t[x] = unite(t[x + 1], t[y]);
  }

  node query(const int x, const int l, const int r, const int ql, const int qr) {
    if (ql <= l and r <= qr) return t[x];
    const int mid = (l + r) / 2;
    const int y = 2 * (mid - l + 1) + x;
    push(x, l, r);
    if (qr <= mid) {
      return query(x + 1, l, mid, ql, qr);
    } else if (mid < ql) {
      return query(y, mid + 1, r, ql, qr);
    } else {
      return unite(query(x + 1, l, mid, ql, qr),
                   query(y, mid + 1, r, ql, qr));
    }
  }

public:
  SegTree() : n(0) {}
  SegTree(vector<node> &a) : n(a.size()), t(2 * n - 1) {
    build(0, 0, n - 1, a);
  }

  void decrease(const int l, const int r) {
    decrease(0, 0, n - 1, l, r);
  }

  int query(const int l, const int r) {
    return query(0, 0, n - 1, l, r).mature;
  }
};

SegTree st;

void inicjuj(int N, int K, int *D) {
  vector<node> a(N);
  for (int i = 0; i < N; i++) {
    const int req = (D[i] < K ? K - D[i] : kInf);
    a[i].mini = req;
    a[i].mature = (req == kInf);
  }
  st = SegTree(a);
}

//water the plants
void podlej(int a, int b) {
  st.decrease(a, b);
}

//query mature
int dojrzale(int a, int b) {
  return st.query(a, b);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1628 KB Output is correct
2 Correct 2 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3832 KB Output is correct
2 Correct 25 ms 3688 KB Output is correct
3 Correct 27 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4764 KB Output is correct
2 Correct 40 ms 5092 KB Output is correct
3 Correct 34 ms 4796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 7000 KB Output is correct
2 Correct 50 ms 6456 KB Output is correct
3 Correct 59 ms 6632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 11320 KB Output is correct
2 Correct 104 ms 8656 KB Output is correct
3 Correct 88 ms 10024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 11920 KB Output is correct
2 Correct 95 ms 10600 KB Output is correct
3 Correct 121 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 16692 KB Output is correct
2 Correct 154 ms 15124 KB Output is correct
3 Correct 169 ms 17956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 20732 KB Output is correct
2 Correct 194 ms 20536 KB Output is correct
3 Correct 205 ms 20964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21392 KB Output is correct
2 Correct 203 ms 22160 KB Output is correct
3 Correct 185 ms 21136 KB Output is correct