답안 #494364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494364 2021-12-15T10:28:17 Z jasen_penchev Floppy (RMI20_floppy) C++14
컴파일 오류
0 ms 0 KB
#include "floppy.h"
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <stack>
#define endl '\n'
using namespace std;

const int MAXN = 40000;

int deg[MAXN + 5];
int tsort[MAXN + 5];
vector<int> G[MAXN + 5];
pair<int, int> tree[4 * MAXN + 5];

void save_to_floppy(const string &bits);

void read_array(int subtask_id, const vector<int> &v)
{
    int n = v.size();
    string bits = "";
    stack<int> st;
    for (int i = 0; i < n; ++ i)
    {
        while (st.size() and v[st.top()] < v[i])
        {
            bits += '1';
            st.pop();
        }
        st.push(i);
        bits += '0';
    }

    save_to_floppy(bits);
}

void build(int v, int l, int r)
{
    if (l == r)
    {
        tree[v] = make_pair(tsort[l], l);
        return;
    }

    int mid = (l + r) / 2;
    build(2 * v, l, mid);
    build(2 * v + 1, mid + 1, r);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
}

void query(int v, int l, int r, int L, int R)
{
    if (R < l or r < L) return make_pair(0, -1);
    if (L <= l and r <= R) return tree[v];

    int mid = (l + r) / 2;
    pair<int, int> ret = make_pair(0, -1);
    ret = max(ret, query(2 * v, l, mid, L, R));
    ret = max(ret, query(2 * v + 1, mid + 1, r, L, R));
    return ret;
}

vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b)
{
    int pos = 0;
    stack<int> st;
    for (int i = 0; i < n; ++ i)
    {
        while (bits[pos] == '1')
        {
            G[i].push_back(st.top());
            st.pop();
            pos++;
        }

        if (st.size()) G[st.top()].push_back(i);

        st.push(i);
        pos++;
    }

    for (int u = 0; u < n; ++ u)
    {
        for (auto v : G[u])
        {
            deg[v]++;
        }
    }

    queue<int> q;
    for (int u = 0; u < n; ++ u)
    {
        if (deg[u] == 0) q.push(u);
    }

    for (int i = 0; i < n; ++ i)
    {
        int u = q.front();
        q.pop();

        tsort[u] = n - i;

        for (auto v : G[u])
        {
            deg[v]--;
            if (deg[v] == 0) q.push(v);
        }
    }

    build(1, 0, n - 1);

    vector<int> v;
    int m = a.size();
    for (int i = 0; i < m; ++ i)
    {
        v.push_back(query(1, 0, n - 1, a[i], b[i]).second);
    }

    return v;
}

Compilation message

floppy.cpp: In function 'void query(int, int, int, int, int)':
floppy.cpp:54:41: error: return-statement with a value, in function returning 'void' [-fpermissive]
   54 |     if (R < l or r < L) return make_pair(0, -1);
      |                                ~~~~~~~~~^~~~~~~
floppy.cpp:55:41: error: return-statement with a value, in function returning 'void' [-fpermissive]
   55 |     if (L <= l and r <= R) return tree[v];
      |                                   ~~~~~~^
floppy.cpp:59:25: error: invalid use of void expression
   59 |     ret = max(ret, query(2 * v, l, mid, L, R));
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
floppy.cpp:60:25: error: invalid use of void expression
   60 |     ret = max(ret, query(2 * v + 1, mid + 1, r, L, R));
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
floppy.cpp:61:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   61 |     return ret;
      |            ^~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:91:5: error: 'queue' was not declared in this scope
   91 |     queue<int> q;
      |     ^~~~~
floppy.cpp:7:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
    6 | #include <stack>
  +++ |+#include <queue>
    7 | #define endl '\n'
floppy.cpp:91:11: error: expected primary-expression before 'int'
   91 |     queue<int> q;
      |           ^~~
floppy.cpp:94:26: error: 'q' was not declared in this scope
   94 |         if (deg[u] == 0) q.push(u);
      |                          ^
floppy.cpp:99:17: error: 'q' was not declared in this scope
   99 |         int u = q.front();
      |                 ^
floppy.cpp:117:26: error: invalid use of 'void'
  117 |         v.push_back(query(1, 0, n - 1, a[i], b[i]).second);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~