답안 #971804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971804 2024-04-29T10:38:27 Z nguyentunglam Measures (CEOI22_measures) C++17
0 / 100
80 ms 35512 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 4e5 + 30;

int n, m, d;

int a[N];

long long T[4][N << 2];

void up(int s, int l, int r, int pos, int val) {
  if (l == r) {
    T[0][s] = 1;
    T[1][s] = val;
    T[2][s] = d -val;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) up(s << 1, l, mid, pos, val);
  else up(s << 1 | 1, mid + 1, r, pos, val);
  T[0][s] = T[0][s << 1] + T[0][s << 1 | 1];
  T[1][s] = max(T[1][s << 1 | 1], T[1][s << 1] + T[0][s << 1 | 1] * d);
  T[2][s] = max(T[2][s << 1], T[2][s << 1 | 1] + T[0][s << 1] * d);
  T[3][s] = max({T[3][s << 1], T[3][s << 1 | 1], T[1][s << 1] + T[2][s << 1 | 1]});
}

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> m >> d;

  for(int i = 1; i <= n; i++) cin >> a[i];

  for(int i = n + 1; i <= n + m; i++) cin >> a[i];

  vector<pair<int, int> > rrh;

  for(int i = 1; i <= n + m; i++) rrh.emplace_back(a[i], i);

  sort(all(rrh));
  rrh.resize(unique(all(rrh)) - rrh.begin());

  for(int i = 1; i <= 4 * (n + m); i++) T[0][i] = T[1][i] = T[2][i] = -1e18;

  auto update = [&] (int i) {
    int pos = upper_bound(all(rrh), make_pair(a[i], i)) - rrh.begin();
//    cout << pos << endl;
    up(1, 1, n + m, pos, a[i]);
  };

  for(int i = 1; i <= n; i++) update(i);

  for(int i = n + 1; i <= n + m; i++) {
    update(i);
    cout << T[3][1] / 2;
    if (T[3][1] % 2) cout << ".5";
    cout << " ";
  }
}



Compilation message

Main.cpp: In function 'void up(int, int, int, int, int)':
Main.cpp:21:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |   int mid = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'int32_t main()':
Main.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 35512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 35512 KB Output isn't correct
2 Halted 0 ms 0 KB -