Submission #488375

# Submission time Handle Problem Language Result Execution time Memory
488375 2021-11-18T19:08:45 Z alexander707070 Floppy (RMI20_floppy) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "floppy.h"
using namespace std;

string s;
int curr;

/*
void save_to_floppy(string ss){

}
*/

void read_array (int subtask_id,const vector<int> &v){
    for(int i=0;i<v.size();i++){
        curr=v[i];
        if(v[i]>=0)s.push_back('0');
        else s.push_back('1');

        v[i]=abs(v[i]);
        for(int f=0;f<30;f++){
            s.push_back(v[i]%2+'0');
            v[i]/=2;
        }
        v[i]=curr;
    }
    save_to_floppy(s);
}

int c[80007],p;

bool li[80007][20];
int dp[80007][20];
int power[20],lg[80007];

void calc(){
    power[0]=1;
    for(int i=1;i<20;i++)power[i]=power[i-1]*2;
    lg[1]=0;
    for(int i=2;i<=80000;i++)lg[i]=lg[i/2]+1;
}

int best(int x,int y){
    if(c[x]<c[y])return x;
    else return y;
}

int rmq(int i,int j){
    if(j==0)return c[i];

    if(li[i][j])return dp[i][j];
    li[i][j]=true;

    dp[i][j]=best(rmq(i,j-1),rmq(i+power[j-1],j-1));
    return dp[i][j];
}
int mins(int l,int r){
    return best( rmq(l,lg[r-l+1]) , rmq(r-power[lg[r-l+1]]+1,lg[r-l+1]) );
}

vector<int> ans;

vector<int> solve_queries(int subtask_id,int N,const string &bits,const vector<int> &a,const vector<int> &b){
    for(int i=0;i<bits.size();i+=31){
        for(int f=i+1;f<=i+30;f++){
            c[p]+=(bits[f]-'0');
            c[p]*=2;
        }
        if(bits[i]=='1')c[p]*=-1;
        p++;
    }
    calc();
    for(int i=0;i<a.size();i++){
        ans.push_back(mins(a[i],b[i]));
    }
    return ans;
}

/*
int main(){

}
*/

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
floppy.cpp:20:13: error: assignment of read-only location '(& v)->std::vector<int>::operator[](((std::vector<int>::size_type)i))'
   20 |         v[i]=abs(v[i]);
floppy.cpp:23:17: error: assignment of read-only location '(& v)->std::vector<int>::operator[](((std::vector<int>::size_type)i))'
   23 |             v[i]/=2;
floppy.cpp:25:13: error: assignment of read-only location '(& v)->std::vector<int>::operator[](((std::vector<int>::size_type)i))'
   25 |         v[i]=curr;
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<bits.size();i+=31){
      |                 ~^~~~~~~~~~~~
floppy.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~