답안 #719689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719689 2023-04-06T13:43:04 Z peijar Measures (CEOI22_measures) C++17
100 / 100
535 ms 33228 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
  bool first = true;
  string res = "[";
  for (const auto &x : v) {
    if (!first)
      res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "]";
  return res;
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << to_string(H);
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

template <class T> class Fenwick {
public:
  int lim;
  vector<T> bit;

  Fenwick(int n) : lim(n + 1), bit(lim) {}

  void upd(int pos, T val) {
    for (pos++; pos < lim; pos += pos & -pos)
      bit[pos] += val;
  }

  T sum(int r) { // < r
    T ret = 0;
    for (; r; r -= r & -r)
      ret += bit[r];
    return ret;
  }

  T sum(int l, int r) { // [l, r)
    return sum(r) - sum(l);
  }
};

const int MAXN = 2e6;

int iDeb[MAXN], iFin[MAXN], lazyAdd[MAXN], maxDiff[MAXN], minVal[MAXN],
    maxVal[MAXN];

void pull(int node) {
  maxVal[node] = max(maxVal[2 * node], maxVal[2 * node + 1]);
  minVal[node] = min(minVal[2 * node], minVal[2 * node + 1]);
  maxDiff[node] = max({maxDiff[2 * node], maxDiff[2 * node + 1],
                       maxVal[2 * node + 1] - minVal[2 * node]});
}

void push(int node) {
  if (!lazyAdd[node])
    return;
  int x = lazyAdd[node];
  lazyAdd[node] = 0;

  maxVal[node] += x;
  minVal[node] += x;
  if (iDeb[node] < iFin[node]) {
    lazyAdd[2 * node] += x;
    lazyAdd[2 * node + 1] += x;
  }
}

void build(int node, int l, int r) {
  iDeb[node] = l, iFin[node] = r;
  maxVal[node] = -1e18;
  minVal[node] = 1e18;

  if (l == r)
    return;

  build(2 * node, l, (l + r) / 2);
  build(2 * node + 1, (l + r) / 2 + 1, r);
}

void active(int node, int pos, int val) {
  push(node);
  if (iDeb[node] > pos or iFin[node] < pos)
    return;
  if (iDeb[node] == iFin[node]) {
    minVal[node] = maxVal[node] = val;
    return;
  }
  active(2 * node, pos, val);
  active(2 * node + 1, pos, val);
  pull(node);
}

void rangeAdd(int node, int l, int r, int x) {
  push(node);
  if (iDeb[node] > r or iFin[node] < l) {
    return;
  }
  if (iDeb[node] >= l and iFin[node] <= r) {
    lazyAdd[node] = x;
    push(node);
    return;
  }
  rangeAdd(2 * node, l, r, x);
  rangeAdd(2 * node + 1, l, r, x);
  pull(node);
}

string affiche(int x) {
  if (x % 2)
    return to_string(x / 2) + ".5";
  return to_string(x / 2);
}

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbPersonnes, nbRequetes, D;
  cin >> nbPersonnes >> nbRequetes >> D;

  vector<pair<int, int>> positions(nbPersonnes + nbRequetes);
  vector<int> toAdd;
  for (int i = 0; i < nbPersonnes; ++i) {
    int x;
    cin >> x;
    positions[i] = pair(x, i);
    toAdd.push_back(x);
  }
  for (int i = 0; i < nbRequetes; ++i) {
    int x;
    cin >> x;
    positions[i + nbPersonnes] = pair(x, nbPersonnes + i);
    toAdd.push_back(x);
  }

  sort(positions.begin(), positions.end());
  build(1, 0, nbPersonnes + nbRequetes - 1);
  Fenwick<int> activated(nbPersonnes + nbRequetes);

  for (int i = 0; i < nbPersonnes + nbRequetes; ++i) {
    int pos =
        lower_bound(positions.begin(), positions.end(), pair(toAdd[i], i)) -
        positions.begin();
    assert(positions[pos] == pair(toAdd[i], i));
    int bef = activated.sum(pos);
    activated.upd(pos, 1);
    active(1, pos, D * bef - toAdd[i]);
    rangeAdd(1, pos + 1, nbPersonnes + nbRequetes - 1, D);
    if (i >= nbPersonnes)
      cout << affiche(maxDiff[1]) << ' ';
  }
  cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 475 ms 29336 KB Output is correct
10 Correct 339 ms 30020 KB Output is correct
11 Correct 183 ms 30108 KB Output is correct
12 Correct 197 ms 29876 KB Output is correct
13 Correct 161 ms 29900 KB Output is correct
14 Correct 198 ms 30012 KB Output is correct
15 Correct 359 ms 29892 KB Output is correct
16 Correct 195 ms 29924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 30356 KB Output is correct
2 Correct 207 ms 32208 KB Output is correct
3 Correct 203 ms 33032 KB Output is correct
4 Correct 179 ms 30964 KB Output is correct
5 Correct 208 ms 32136 KB Output is correct
6 Correct 192 ms 31260 KB Output is correct
7 Correct 208 ms 32256 KB Output is correct
8 Correct 189 ms 30908 KB Output is correct
9 Correct 192 ms 30864 KB Output is correct
10 Correct 198 ms 33228 KB Output is correct
11 Correct 183 ms 31640 KB Output is correct
12 Correct 200 ms 32628 KB Output is correct
13 Correct 186 ms 30916 KB Output is correct
14 Correct 208 ms 32816 KB Output is correct
15 Correct 187 ms 32616 KB Output is correct
16 Correct 219 ms 30924 KB Output is correct
17 Correct 212 ms 32092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 30356 KB Output is correct
2 Correct 207 ms 32208 KB Output is correct
3 Correct 203 ms 33032 KB Output is correct
4 Correct 179 ms 30964 KB Output is correct
5 Correct 208 ms 32136 KB Output is correct
6 Correct 192 ms 31260 KB Output is correct
7 Correct 208 ms 32256 KB Output is correct
8 Correct 189 ms 30908 KB Output is correct
9 Correct 192 ms 30864 KB Output is correct
10 Correct 198 ms 33228 KB Output is correct
11 Correct 183 ms 31640 KB Output is correct
12 Correct 200 ms 32628 KB Output is correct
13 Correct 186 ms 30916 KB Output is correct
14 Correct 208 ms 32816 KB Output is correct
15 Correct 187 ms 32616 KB Output is correct
16 Correct 219 ms 30924 KB Output is correct
17 Correct 212 ms 32092 KB Output is correct
18 Correct 366 ms 31220 KB Output is correct
19 Correct 535 ms 32688 KB Output is correct
20 Correct 189 ms 32704 KB Output is correct
21 Correct 250 ms 30748 KB Output is correct
22 Correct 288 ms 31144 KB Output is correct
23 Correct 206 ms 30888 KB Output is correct
24 Correct 431 ms 31520 KB Output is correct
25 Correct 216 ms 30676 KB Output is correct
26 Correct 385 ms 30664 KB Output is correct
27 Correct 406 ms 33100 KB Output is correct
28 Correct 283 ms 30996 KB Output is correct
29 Correct 365 ms 32360 KB Output is correct
30 Correct 224 ms 30580 KB Output is correct
31 Correct 236 ms 32524 KB Output is correct
32 Correct 195 ms 32476 KB Output is correct
33 Correct 400 ms 30604 KB Output is correct
34 Correct 217 ms 31828 KB Output is correct