Submission #494365

# Submission time Handle Problem Language Result Execution time Memory
494365 2021-12-15T10:28:42 Z jasen_penchev Floppy (RMI20_floppy) C++14
Compilation error
0 ms 0 KB
#include "floppy.h"
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <queue>
#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:55:41: error: return-statement with a value, in function returning 'void' [-fpermissive]
   55 |     if (R < l or r < L) return make_pair(0, -1);
      |                                ~~~~~~~~~^~~~~~~
floppy.cpp:56:41: error: return-statement with a value, in function returning 'void' [-fpermissive]
   56 |     if (L <= l and r <= R) return tree[v];
      |                                   ~~~~~~^
floppy.cpp:60:25: error: invalid use of void expression
   60 |     ret = max(ret, query(2 * v, l, mid, L, R));
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
floppy.cpp:61:25: error: invalid use of void expression
   61 |     ret = max(ret, query(2 * v + 1, mid + 1, r, L, R));
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
floppy.cpp:62:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   62 |     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:118:26: error: invalid use of 'void'
  118 |         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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~