Submission #1097445

# Submission time Handle Problem Language Result Execution time Memory
1097445 2024-10-07T11:58:14 Z avighna Meteors (POI11_met) C++17
74 / 100
509 ms 65536 KB
#include <bits/stdc++.h>

typedef long long ll;

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

  FenwickTree(ll n) {
    this->n = n;
    f.resize(n + 1);
  }

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

  ll query(ll idx) {
    ll ans = 0;
    for (ll i = idx; i >= 1; i -= i & (-i)) {
      ans += f[i];
    }
    return ans;
  }
  ll query(ll l, ll r) {
    if (l > r) {
      return 0;
    }
    ll ans = query(r);
    if (l - 1 >= 1) {
      ans -= query(l - 1);
    }
    return ans;
  }
};

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

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

  struct State {
    ll i, l, r;
  };
  std::vector midpoints(k + 1, std::vector<State>());
  for (ll i = 0; i < n; ++i) {
    midpoints[(k + 1) / 2].push_back({i, 1, k});
  }
  std::vector<ll> ans(n, k + 1);
  for (ll j = 0; j < 30; ++j) {
    FenwickTree tree(m + 1);
    auto apply = [&](ll l, ll r, ll d) {
      tree.add(l, d);
      tree.add(r + 1, -d);
    };
    bool changed = false;
    for (ll i = 1; i <= k; ++i) {
      if (upd[i - 1].l <= upd[i - 1].r) {
        apply(upd[i - 1].l, upd[i - 1].r, upd[i - 1].a);
      } else {
        apply(upd[i - 1].l, m, upd[i - 1].a);
        apply(1, upd[i - 1].r, upd[i - 1].a);
      }
      while (!midpoints[i].empty()) {
        changed = true;
        auto [_i, l, r] = midpoints[i].back();
        midpoints[i].pop_back();
        if (l > r) {
          continue;
        }
        ll obtained = 0;
        for (auto &x : owned[_i + 1]) {
          obtained += tree.query(x);
        }
        if (obtained >= p[_i + 1]) {
          ans[_i] = std::min(ans[_i], i);
          midpoints[(l + i - 1) / 2].push_back({_i, l, i - 1});
        } else {
          midpoints[(i + r + 1) / 2].push_back({_i, i + 1, r});
        }
      }
    }
    if (!changed) {
      break;
    }
  }
  for (auto &i : ans) {
    if (i == k + 1) {
      std::cout << "NIE\n";
    } else {
      std::cout << i << '\n';
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 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 1 ms 604 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 52 ms 6884 KB Output is correct
2 Correct 97 ms 16124 KB Output is correct
3 Correct 73 ms 11716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 9936 KB Output is correct
2 Correct 77 ms 9928 KB Output is correct
3 Correct 107 ms 16596 KB Output is correct
4 Correct 22 ms 8020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 7152 KB Output is correct
2 Correct 70 ms 16404 KB Output is correct
3 Correct 28 ms 3676 KB Output is correct
4 Correct 68 ms 13384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 4688 KB Output is correct
2 Correct 83 ms 10028 KB Output is correct
3 Correct 43 ms 5836 KB Output is correct
4 Correct 97 ms 18700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 414 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 509 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -