제출 #310182

#제출 시각아이디문제언어결과실행 시간메모리
310182LifeHappen__Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
195 ms7552 KiB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a), end(a)

const int N = 2e5 + 5;
int n, b[N], it[N << 2], ans[N];
ii a[N];

void upd(int i, int l, int r, int pos, int val) {
  if (pos < l || pos > r) return;
  if (l == r) {
    it[i] = val;
    return;
  }
  int m = (l + r) / 2;
  upd(i << 1, l, m, pos, val);
  upd(i << 1 | 1, m + 1, r, pos, val);
  it[i] = max(it[i << 1], it[i << 1 | 1]);
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

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

  cin >> n;
  for (int i = 1; i <= n + 1; ++i) {
    cin >> a[i].fi;
    a[i].se = i;
  }
  for (int i = 1; i <= n; ++i)
    cin >> b[i];
  sort(a + 1, a + n + 2);
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    upd(1, 1, n, i, a[i + 1].fi - b[i]);
  for (int i = 1; i <= n + 1; ++i) {
    ans[a[i].se] = it[1];
    upd(1, 1, n, i, a[i].fi - b[i]);
  }
  for (int i = 1; i <= n + 1; ++i)
    cout << ans[i] << ' ';
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t1.cpp: In function 'int32_t main()':
ho_t1.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.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".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...