Submission #1049657

# Submission time Handle Problem Language Result Execution time Memory
1049657 2024-08-09T03:39:23 Z QuangBui Meteors (POI11_met) C++17
87 / 100
1043 ms 59092 KB
// QuangBuiCP
// https://oj.uz/problem/view/POI11_met
#include "bits/stdc++.h"
using namespace std;

int main() {
#ifndef LOCAL
  cin.tie(nullptr)->sync_with_stdio(false);
#endif // LOCAL

  int n, m;
  cin >> n >> m;
  vector<vector<int>> properties(n);
  for (int i = 0; i < m; ++i) {
    int who;
    cin >> who;
    properties[--who].push_back(i);
  }
  vector<int> target(n);
  for (int i = 0; i < n; ++i) {
    cin >> target[i];
  }
  int events;
  cin >> events;
  vector<tuple<int, int, int>> event(events);
  for (auto& [l, r, collectable] : event) {
    cin >> l >> r >> collectable;
    l--, r--;
  }
  vector<vector<int>> candidates(events + 1);
  vector<int> L(n, 0), R(n, events - 1);
  vector<int> answer(n, -1);
  for (int step = 0; step < 20; ++step) {
    for (int i = 0; i < n; ++i) {
      if (L[i] > R[i]) {
        continue;
      }
      int mid = (L[i] + R[i]) / 2;
      candidates[mid].push_back(i);
    }
    vector<int> fenw(m + 1, 0);
    auto Update = [&fenw, &m](int x, int val) {
      while (x <= m) {
        fenw[x] += val;
        x |= x + 1;
      }
    };
    auto UpdateRange = [&fenw, &m, &Update](int l, int r, int val) {
      Update(l, val);
      Update(r + 1, -val);
    };
    auto Query = [&fenw](int x) {
      int res = 0;
      while (x >= 0) {
        res += fenw[x];
        x &= x + 1;
        x--;
      }
      return res;
    };
    for (int mid = 0; mid < events; ++mid) {
      auto [l, r, collectable] = event[mid];
      if (l <= r) {
        UpdateRange(l, r, collectable);
      } else {
        UpdateRange(l, m - 1, collectable);
        UpdateRange(0, r, collectable);
      }
      for (int who : candidates[mid]) {
        int sum = 0;
        for (int land : properties[who]) {
          sum += Query(land);
          if (sum >= target[who]) {
            break;
          }
        }
        if (sum >= target[who]) {
          answer[who] = mid;
          R[who] = mid - 1;
        } else {
          L[who] = mid + 1;
        }
      }
      candidates[mid].clear();
    }
  }

  for (int i = 0; i < n; ++i) {
    if (answer[i] == -1) {
      cout << "NIE\n";
    } else {
      cout << answer[i] + 1 << '\n';
    }
  }

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4240 KB Output is correct
2 Correct 73 ms 7296 KB Output is correct
3 Correct 59 ms 6028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 5440 KB Output is correct
2 Correct 62 ms 5400 KB Output is correct
3 Correct 79 ms 7468 KB Output is correct
4 Correct 16 ms 3340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4560 KB Output is correct
2 Correct 52 ms 7820 KB Output is correct
3 Correct 28 ms 2908 KB Output is correct
4 Correct 57 ms 6592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 3736 KB Output is correct
2 Correct 65 ms 5720 KB Output is correct
3 Correct 60 ms 4144 KB Output is correct
4 Correct 71 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 740 ms 37544 KB Output is correct
2 Correct 429 ms 21284 KB Output is correct
3 Correct 131 ms 11604 KB Output is correct
4 Correct 1043 ms 59092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 720 ms 36008 KB Output is correct
2 Correct 480 ms 19628 KB Output is correct
3 Incorrect 108 ms 11088 KB Output isn't correct
4 Halted 0 ms 0 KB -