답안 #494334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494334 2021-12-15T07:38:06 Z Tenis0206 Floppy (RMI20_floppy) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "floppy.h"

using namespace std;

/*string bglobal;

void save_to_floppy(string bits)
{
    bglobal = bits;
}
*/

void read_array(int subtask, const vector<int> &v)
{
    stack<int> st;
    string bits;
    for(int i=0;i<v.size();i++)
    {
        while(!st.empty() && v[i]>v[st.top()])
        {
            bits.push_back('0');
            st.pop();
        }
        bits.push_back('1');
        st.push(i);
    }
    save_to_floppy(bits);
}

int rmq[25][100005];
int Log2[100005];

int l[100005];

void build_rmq(int n)
{
    for(int i=2;i<=n;i++)
    {
        Log2[i] = 1 + Log2[i/2];
    }
    for(int i=1;i<=n;i++)
    {
        rmq[0][i] = i;
    }
    for(int k=1;k<=Log2[n];k++)
    {
        for(int i=1;i<=n;i++)
        {
            if(l[rmq[k-1][i]]<l[rmq[k-1][i+(1<<(k-1))]])
            {
                rmq[k][i] = rmq[k-1][i];
            }
            else
            {
                rmq[k][i] = rmq[k-1][i+(1<<(k-1))];
            }
        }
    }
}

int query(int x, int y)
{
    int k = y - x + 1;
    k = Log2[k];
    if(l[rmq[k][x]]<l[rmq[k][y-(1<<k)+1]])
    {
        return rmq[k][x];
    }
    return rmq[k][y-(1<<k)+1];
}

vector<int> solve_queries(int subtask, int n, const string bits, const vector<int> &a, const vector<int> &b)
{
    stack<int> st;
    int poz = 0;
    for(int i=1;i<=n;i++)
    {
        while(poz<bits.size() && bits[poz]=='0')
        {
            ++poz;
            st.pop();
        }
        if(st.empty())
        {
            l[i] = 0;
        }
        else
        {
            l[i] = st.top();
        }
        ++poz;
        st.push(i);
    }
    build_rmq(n);
    vector<int> rez;
    for(int i=0;i<a.size();i++)
    {
        int x = a[i] + 1;
        int y = b[i] + 1;
        rez.push_back(query(x,y)-1);
    }
    return rez;
}

/*int main()
{
    int n;
    cin>>n;
    vector<int> v;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    int q;
    cin>>q;
    vector<int> a,b;
    for(int i=1;i<=q;i++)
    {
        int x,y;
        cin>>x>>y;
        a.push_back(x);
        b.push_back(y);
    }
    read_array(0,v);
    vector<int> rez = solve_queries(0,n,bglobal,a,b);
    for(auto it : rez)
    {
        cout<<it<<' ';
    }
    return 0;
}
*/

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, std::string, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         while(poz<bits.size() && bits[poz]=='0')
      |               ~~~^~~~~~~~~~~~
floppy.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0;i<a.size();i++)
      |                 ~^~~~~~~~~
stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     if (query_answers.size() != M) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
/usr/bin/ld: /tmp/ccnXK9IV.o: in function `run2()':
stub.cpp:(.text+0x698): undefined reference to `solve_queries(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status