답안 #1081626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081626 2024-08-30T08:22:38 Z juicy Autobahn (COI21_autobahn) C++17
100 / 100
186 ms 22088 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;

int n, k, L;
int l[N], r[N], t[N], a[9 * N], b[9 * N];
long long pf[9 * N];

void upd(int i, int j, int *a) {
  ++a[i];
  --a[j];
}

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

  cin >> n >> k >> L;
  vector<int> comp;
  for (int i = 1; i <= n; ++i) {
    cin >> l[i] >> t[i] >> r[i];
    comp.push_back(l[i]);
    comp.push_back(r[i] + 1);
    if (r[i] - l[i] + 1 <= t[i]) {
      t[i] = -1;
      continue;
    }
    comp.push_back(l[i] + t[i]);
  }
  int m = comp.size();
  for (int i = 0; i < m; ++i) {
    comp.push_back(comp[i] + L);
    comp.push_back(comp[i] - L);
  }
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  auto pos = [&](int i) {
    return lower_bound(comp.begin(), comp.end(), i) - comp.begin() + 1;
  };
  m = comp.size();
  for (int i = 1; i <= n; ++i) {
    int x = pos(l[i]), y = pos(r[i] + 1);
    upd(x, y, a);
    if (~t[i]) {
      int z = pos(l[i] + t[i]);
      upd(z, y, b);
    }
  }
  for (int i = 1; i <= m; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
    if (i + 1 <= m) {
      pf[i + 1] = pf[i] + (long long) (comp[i] - comp[i - 1]) * (a[i] >= k ? b[i] : 0);
    }
  }
  long long res = 0;
  for (int i = 1; i <= m; ++i) {
    int y = pos(comp[i - 1] + L);
    if (y <= m && comp[y - 1] == comp[i - 1] + L) {
      res = max(res, pf[y] - pf[i]);
    }
  }
  cout << res;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 612 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 612 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 186 ms 22076 KB Output is correct
22 Correct 171 ms 21952 KB Output is correct
23 Correct 167 ms 22080 KB Output is correct
24 Correct 160 ms 22088 KB Output is correct
25 Correct 159 ms 21944 KB Output is correct
26 Correct 155 ms 21948 KB Output is correct
27 Correct 160 ms 22028 KB Output is correct
28 Correct 150 ms 21972 KB Output is correct
29 Correct 152 ms 21960 KB Output is correct