답안 #1049693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049693 2024-08-09T04:04:27 Z QuangBui Meteors (POI11_met) C++17
100 / 100
1153 ms 59548 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<int64_t> target(n);
  for (int64_t& it : target) {
    cin >> it;
  }
  int event;
  cin >> event;
  vector<tuple<int, int, int64_t>> events(event);
  for (auto& [l, r, collectable] : events) {
    cin >> l >> r >> collectable;
    l--, r--;
  }
 
  vector<vector<int>> candidates(event + 1);
  vector<int> L(n, 0), R(n, event - 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<int64_t> fenw(m + 1, 0);
    auto Update = [&fenw, &m](int x, int64_t val) {
      while (x <= m) {
        fenw[x] += val;
        x |= x + 1;
      }
    };
    auto UpdateRange = [&fenw, &m, &Update](int l, int r, int64_t val) {
      Update(l, val);
      Update(r + 1, -val);
    };
    auto Query = [&fenw](int x) {
      int64_t res = 0;
      while (x >= 0) {
        res += fenw[x];
        x &= x + 1;
        x--;
      }
      return res;
    };
    for (int mid = 0; mid < event; ++mid) {
      auto [l, r, collectable] = events[mid];
      if (l <= r) {
        UpdateRange(l, r, collectable);
      } else {
        UpdateRange(l, m - 1, collectable);
        UpdateRange(0, r, collectable);
      }
      for (int who : candidates[mid]) {
        int64_t 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 x : answer) {
    if (x == -1) {
      cout << "NIE\n";
    } else {
      cout << x + 1 << '\n';
    }
  }
 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 3760 KB Output is correct
2 Correct 99 ms 6756 KB Output is correct
3 Correct 64 ms 5576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 4808 KB Output is correct
2 Correct 73 ms 4788 KB Output is correct
3 Correct 90 ms 6604 KB Output is correct
4 Correct 15 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 4044 KB Output is correct
2 Correct 58 ms 7116 KB Output is correct
3 Correct 27 ms 2396 KB Output is correct
4 Correct 64 ms 6076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 3028 KB Output is correct
2 Correct 78 ms 4808 KB Output is correct
3 Correct 50 ms 3272 KB Output is correct
4 Correct 86 ms 7628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 811 ms 32420 KB Output is correct
2 Correct 544 ms 15700 KB Output is correct
3 Correct 129 ms 10320 KB Output is correct
4 Correct 1041 ms 54124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 808 ms 30988 KB Output is correct
2 Correct 503 ms 15832 KB Output is correct
3 Correct 110 ms 8284 KB Output is correct
4 Correct 1153 ms 59548 KB Output is correct