답안 #1056630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056630 2024-08-13T10:23:48 Z mychecksedad 송신탑 (IOI22_towers) C++17
컴파일 오류
0 ms 0 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pi pair<int,int>
#define vi vector<int> 
#define ff first
#define ss second


void op(vector<int> &a, vector<int> &A, vector<int> &B){
  if(a.size() <= 1){
    A = a;
    B = 0;
    return;
  }
  A.pb(a[0]);
  A.pb(a[1]);
  B.pb(0);
  B.pb(1);
  for(int i = 2; i < a.size(); ++i){
    if(a[i] > A.back() && A.back() > A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else if(a[i] < A.back() && A.back() < A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else{
      A.pb(a[i]);
      B.pb(i);
    }
  }
  
}
int n;
vector<int> A, B, A2, A1, B1, B2;
void init(int nn, std::vector<int> a) { n=nn;
  if(n == 1) return;
  op(a, A, B);
  vector<int> x, y;
  for(int i = 0; i < A.size(); i += 2){
    x.pb(A[i]);
  }
  for(int i = 1; i < A.size(); i += 2){
    y.pb(A[i]);
  }
  op(y, A2, B2);
  op(x, A1, B1);
}

int max_towers(int L, int R, int D) {
  if(n == 1) return 1;
  int l = L, r = R;
  L = lower_bound(all(B), L) - B.begin();
  R = upper_bound(all(B), R) - B.begin(); --R;
  // cout << "f";
  if(R < L) return min(r-l+1, 2);
  if(L == R) return min(r-l+1, 2);
  if(A[L] > A[L + 1]){
    // if(L%2==0){
    //   int Lx = lower_bound(all(B1), L) - B1.begin();
    //   int Rx = upper_bound(all(B1), R) - B1.begin(); --Rx;
    //   if((Rx-Lx+1)/2 > max(min(2,r-l+1),(R-L+1)/2)) return (Rx-Lx+1)/2;
    // }
    // if(L%2==1){
    //   int Lx = lower_bound(all(B2), L) - B2.begin();
    //   int Rx = upper_bound(all(B2), R) - B2.begin(); --Rx;
    //   if((Rx-Lx+1)/2 > max(min(2,r-l+1),(R-L+1)/2)) return (Rx-Lx+1)/2;
    // }

    return max(min(2,r-l+1),(R-L+2)/2);
  }
  return max(min(2,r-l+1), (R-L+2)/2);
}

Compilation message

towers.cpp: In function 'void op(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
towers.cpp:17:9: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
   17 |     B = 0;
      |         ^
In file included from /usr/include/c++/10/vector:72,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from towers.h:1,
                 from towers.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
towers.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i = 2; i < a.size(); ++i){
      |                  ~~^~~~~~~~~~
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int i = 0; i < A.size(); i += 2){
      |                  ~~^~~~~~~~~~
towers.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int i = 1; i < A.size(); i += 2){
      |                  ~~^~~~~~~~~~