Submission #1097472

# Submission time Handle Problem Language Result Execution time Memory
1097472 2024-10-07T12:47:12 Z avighna Meteors (POI11_met) C++17
74 / 100
717 ms 65536 KB
#include <bits/stdc++.h>

class FenwickTree {
public:
  std::vector<long long> f;
  int n;

  FenwickTree(int n) : n(n) { f.resize(n + 1); }

  void add(int idx, int del) {
    for (int i = idx; i <= n; i += i & (-i)) {
      f[i] += del;
    }
  }

  long long query(int idx) {
    long long ans = 0;
    for (int i = idx; i >= 1; i -= i & (-i)) {
      ans += f[i];
    }
    return ans;
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, m;
  std::cin >> n >> m;
  std::vector owned(n + 1, std::vector<int>());
  for (int i = 1, x; i <= m; ++i) {
    std::cin >> x;
    owned[x].push_back(i);
  }
  std::vector<long long> p(n + 1);
  for (int i = 1; i <= n; ++i) {
    std::cin >> p[i];
  }
  int k;
  std::cin >> k;
  struct Update {
    int l, r;
    long long a;
  };
  std::vector<Update> upd(k);
  for (auto &[l, r, a] : upd) {
    std::cin >> l >> r >> a;
  }

  struct State {
    int i, l, r;
  };
  std::vector midpoints(k, std::vector<State>());
  for (int i = 0; i < n; ++i) {
    midpoints[(k - 1) / 2].push_back({i, 0, k - 1});
  }
  std::vector<int> ans(n, k);
  while (true) {
    bool changed = false;
    FenwickTree tree(m + 1);
    auto apply = [&](int l, int r, int d) {
      tree.add(l, d);
      tree.add(r + 1, -d);
    };
    for (int i = 0; i < k; ++i) {
      if (upd[i].l <= upd[i].r) {
        apply(upd[i].l, upd[i].r, upd[i].a);
      } else {
        apply(upd[i].l, m, upd[i].a);
        apply(1, upd[i].r, upd[i].a);
      }
      while (!midpoints[i].empty()) {
        changed = true;
        auto [_i, l, r] = midpoints[i].back();
        midpoints[i].pop_back();
        if (l > r) {
          continue;
        }
        long long obtained = 0;
        for (auto &x : owned[_i + 1]) {
          obtained += tree.query(x);
          if (obtained >= p[_i + 1]) {
            break;
          }
        }
        if (obtained >= p[_i + 1]) {
          ans[_i] = std::min(ans[_i], i);
        }
        if (l < r) {
          if (obtained >= p[_i + 1] and l + i - 1 >= 0) {
            midpoints[(l + i - 1) / 2].push_back({_i, l, i - 1});
          }
          if (obtained < p[_i + 1] and i + r + 1 < 2 * k) {
            midpoints[(i + r + 1) / 2].push_back({_i, i + 1, r});
          }
        }
      }
    }
    if (!changed) {
      break;
    }
  }
  for (auto &i : ans) {
    if (i == k) {
      std::cout << "NIE\n";
    } else {
      std::cout << i + 1 << '\n';
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 5208 KB Output is correct
2 Correct 91 ms 10332 KB Output is correct
3 Correct 99 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 7052 KB Output is correct
2 Correct 102 ms 7308 KB Output is correct
3 Correct 90 ms 10800 KB Output is correct
4 Correct 20 ms 5172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 5580 KB Output is correct
2 Correct 68 ms 11000 KB Output is correct
3 Correct 31 ms 3164 KB Output is correct
4 Correct 74 ms 9192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4052 KB Output is correct
2 Correct 100 ms 7260 KB Output is correct
3 Correct 64 ms 4820 KB Output is correct
4 Correct 107 ms 12224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 653 ms 52084 KB Output is correct
2 Correct 717 ms 21868 KB Output is correct
3 Correct 170 ms 12628 KB Output is correct
4 Runtime error 661 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 683 ms 49072 KB Output is correct
2 Correct 677 ms 20868 KB Output is correct
3 Correct 163 ms 11344 KB Output is correct
4 Runtime error 601 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -