답안 #786097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786097 2023-07-18T03:14:19 Z andecaandeci Exhibition (JOI19_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAXN = 1e5 + 5;
const ll MAX = 1e18;

ll n, m, bingkai[MAXN], ans[MAXN];
pll arr[MAXN], seg[4*MAXN];
// {Size, Value}

pll merge(pll a, pll b) {
  return min(a, b);
}

void build(ll pos, ll l, ll r){
  if (l == r)
  {
    seg[pos] = {arr[l].second, l};
    return ;
  }

  ll mid = (l+r)/2;
  build(pos*2, l, mid);
  build(pos*2+1, mid+1, r);
  seg[pos] = merge(seg[pos*2], seg[pos*2+1]);
}

void update(ll pos, ll l, ll r, ll x) {
  if (l > x || r < x)
  {
    return ;
  }

  if (x <= l && r <= x)
  {
    seg[pos] = {MAX, seg[pos].second};
    return ;
  }

  ll mid = (l+r)/2;
  update(pos*2, l, mid, x);
  update(pos*2+1, mid+1, r, x);
  seg[pos] = merge(seg[pos*2], seg[pos*2+1]);
}

pll query(ll pos, ll l, ll r, ll a, ll b) {
  if (l > b || r < a)
  {
    return {MAX, MAX};
  }

  if (a <= l && r <= b)
  {
    return seg[pos];
  }

  ll mid = (l+r)/2;
  return merge(query(pos*2, l, mid, a, b), query(pos*2+1, mid+1, r, a, b));
}

ll lis() {
  vector<ll> vec;
  for (int i = 1; i <= m; ++i)
  {
    ll now = ans[i];
    // cout << i << " " << now << "\n";
    if (now == MAX)
    {
      continue ;
    }

    ll idx = upper_bound(vec.begin(), vec.end(), now) - vec.begin();
    if (idx == vec.size())
    {
      vec.push_back(now);
    } else {
      vec[idx] = now;
    }
  }

  return vec.size();
}

int main(){
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
  {
    cin >> arr[i].first >> arr[i].second;
  }

  sort(arr+1, arr+n+1);

  for (int i = 1; i <= m; ++i)
  {
    cin >> bingkai[i];
  }

  sort(bingkai+1, bingkai+1+m);

  build(1, 1, n);

  for (int i = 1; i <= m; ++i)
  {
    ans[i] = MAX;
  }

  for (int i = 1; i <= m; ++i)
  {
    ll bingnow = bingkai[i];
    pll tocek = {bingnow, MAX};
    ll idx = upper_bound(arr+1, arr+1+n, tocek) - (arr+1);
    // cout << i << " " << bingnow << " " << idx << "\n";

    if (idx == 0) {
      continue ;
    }

    pll hasil = query(1, 1, n, 1, idx);
    // {Value, Idx}

    if (hasil.first == MAX)
    {
      continue ;
    }

    if (ans[i] != MAX)
    {
      continue ;
    }

    ans[i] = hasil.first;
    update(1, 1, n, hasil.second);
  }

  cout << lis() << "\n";
  return 0;
}

Compilation message

joi2019_ho_t2.cpp: In function 'll lis()':
joi2019_ho_t2.cpp:74:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     if (idx == vec.size())
      |         ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -