제출 #1218032

#제출 시각아이디문제언어결과실행 시간메모리
1218032KindaGoodGamesFloppy (RMI20_floppy)C++20
28 / 100
82 ms4864 KiB
#include <stdlib.h>
#include <string.h>
#include<bits/stdc++.h>

#include "floppy.h"

using namespace std;
int B = 0;
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(); 
    
    B = ceil(log2(n));

    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++){ 
        for(int k = 0; k < B; k++){
            bool on = ((1<<k)&v[i]);
            bits += ('0'+on);
        } 
    }
    cerr << bits<<endl;
    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 = N;
    vector<int> vec(n);
    B = ceil(log2(n));

    for(int i = 0; i < n; i++){
        for(int k = (B*i); k < B*(i+1); k++){
            bool on = bits[k] == '1';
            int pos =(1<<k-( (B*i)));
            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...