Submission #1218022

#TimeUsernameProblemLanguageResultExecution timeMemory
1218022KindaGoodGamesFloppy (RMI20_floppy)C++20
18.45 / 100
83 ms4744 KiB
#include <stdlib.h>
#include <string.h>
#include<bits/stdc++.h>

#include "floppy.h"

using namespace std;
int B = 15;
int INF = numeric_limits<int>::max()/2;
void read_array(int subtask_id, const std::vector<int> &arr) { 
    vector<int >v = arr;
    int n = v.size(); 

    vector<int> sorted = v;
    sort(sorted.begin(),sorted.end());
    map<int,int>toInd;

    for(int i = 0; i < n; i++){
        toInd[sorted[i]] = i;
    }
    for(int i = 0; i < n; i++){
        v[i] = toInd[v[i]];
    }

    string bits = "";
    for(int i = 0; i < n; i++){
        char c = (('0')+ (v[i] < 0));
        bits += c;
        for(int k = 0; k < B; k++){
            bool on = ((1<<k)&v[i]);
            bits += ('0'+on);
        } 
    }
    save_to_floppy(bits);
}
 

std::vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) { 
    int n = bits.size()/(B+1);
    vector<int> vec(n);

    for(int i = 0; i < n; i++){
        for(int k = ((B+1)*i)+1; k < (B+1)*(i+1); k++){
            bool on = bits[k] == '1';
            int pos =(1<<k-( ((B+1)*i)+1));
            vec[i] += on* pos;
        }
    }
    int q = a.size();
    vector<int> answers(q);

    for(int t = 0; t < q; t++){
        int l = a[t];
        int r = b[t];
        int ma = -INF;
        int maInd = -1;

        for(int i = l; i <= r; i++){
            if(ma < vec[i]){
                ma = vec[i];
                maInd = i;
            }
        }
        answers[t] = maInd;
    }

    return answers;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...