답안 #926722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926722 2024-02-13T14:35:23 Z hotboy2703 Floppy (RMI20_floppy) C++14
100 / 100
77 ms 17452 KB
#include "floppy.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXK = 16;
int sp[MAXK][40100];
string ansss;
vector <int> a;
int best(int x,int y){
    if (a[x] > a[y])return x;
    return y;
}
int lg[40100];
int id=0;
void solve(int l,int r,int node = id++){
    if (l > r)return;
    int sz = lg[r-l+1];
    int mid = best(sp[sz][l],sp[sz][r-(1<<sz)+1]);
    ansss[node<<1] = ansss[node<<1|1] = '0';
    if (mid > l){
        solve(l,mid-1);
        ansss[node<<1] = '1';
    }
    if (mid < r){
        ansss[node<<1|1] = '1';
        solve(mid+1,r);
    }
}


int n;
void read_array(int subtask, const vector<int> &v) {
    n = v.size();
    lg[1] = 0;
    for (int i = 2;i <= n;i ++)lg[i] = lg[i/2] + 1;
    a = v;
    for (int i = 0;i < n;i ++){
        sp[0][i] = i;
    }
    for (int j = 1;j < MAXK;j ++){
        for (int i = 0;i + (1<<j) - 1 < n;i++){
            sp[j][i] = best(sp[j-1][i],sp[j-1][i+(1<<(j-1))]);
        }
    }
    ansss.resize(2*n);
    solve(0,n-1);
    save_to_floppy(ansss);
}
string mom;
int cur = 0;
int depth[40100];
int sex[40100];
void decode(int node = id++){
    if (mom[node<<1] == '1'){
        decode();
    }
    sex[cur++] = node;
    if (mom[node<<1|1] == '1'){
        decode();
    }
}
int best2(int x,int y){
    if (sex[x] < sex[y])return x;
    return y;
}
vector<int> solve_queries(int subtask, int n, const string &data, const vector<int> &a,const vector<int> &b) {
    vector<int> anssswer(a.size());
    lg[1] = 0;
    for (int i = 2;i <= n;i ++){
        lg[i] = lg[i>>1] + 1;
    }
    mom = data;
    id = 0;
    cur = 0;
    decode();
    for (int i = 0;i < n;i ++){
        sp[0][i] = i;
    }
    for (int j = 1;j < MAXK;j ++){
        for (int i = 0;i + (1<<j) - 1 < n;i ++){
            sp[j][i] = best2(sp[j-1][i],sp[j-1][i + (1<<(j-1))]);
        }
    }
    for (int i = 0;i < a.size();i++){
        int l = a[i];
        int r = b[i];
        int sz = lg[r - l + 1];
        anssswer[i] = best2(sp[sz][l],sp[sz][r - (1<<sz) + 1]);
    }
    return anssswer;
}

Compilation message

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5084 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 2 ms 4920 KB Output is correct
4 Correct 2 ms 4916 KB Output is correct
5 Correct 2 ms 4932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 7596 KB Output is correct
2 Correct 16 ms 7600 KB Output is correct
3 Correct 16 ms 7608 KB Output is correct
4 Correct 16 ms 7940 KB Output is correct
5 Correct 22 ms 7608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 16612 KB Output is correct
2 Correct 68 ms 16804 KB Output is correct
3 Correct 72 ms 16688 KB Output is correct
4 Correct 77 ms 17452 KB Output is correct
5 Correct 69 ms 16596 KB Output is correct