답안 #494783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494783 2021-12-16T10:58:33 Z robertbarbu27 Floppy (RMI20_floppy) C++14
100 / 100
129 ms 22244 KB
#include<bits/stdc++.h>
#include "floppy.h"
using namespace std;
 
string s;
vector<int> vv;
 
int num;
struct node{
    int num;
    int pos;
    int sz;
    int l;
    int r;
};
 
node tree[80007];
 
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(vv[x]>vv[y])return x;
    else return y;
}
 
int rmq(int i,int j){
    if(j==0)return 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]) );
}
 
void build(int p,int l,int r){
    if(l>r)return;
    if(l==r){
        num++;
        tree[num].pos=l;
        if(l<tree[p].pos)tree[p].l=num;
        else tree[p].r=num;
    }else{
        int id=mins(l,r);
        num++;
        tree[num].pos=id;
        if(p!=-1){
            if(id<tree[p].pos)tree[p].l=num;
            else tree[p].r=num;
        }
        int pum=num;
        build(pum,l,id-1);
        build(pum,id+1,r);
    }
}
void dfs(int x){
    if(tree[x].l!=0)s.push_back('1');
    else s.push_back('0');
 
    if(tree[x].r!=0)s.push_back('1');
    else s.push_back('0');  
 
    if(tree[x].l!=0)dfs(tree[x].l);
    if(tree[x].r!=0)dfs(tree[x].r);
}
 
void read_array(int subtask_id,const vector<int> &v){
    for(int i=0;i<v.size();i++)vv.push_back(v[i]);
    calc();
    build(-1,0,int(v.size())-1);
    dfs(1);
    save_to_floppy(s);
}
 
int c[80007];
 
int restore(int pos,int dep,int toadd){
    int sz=1;
    if(s[pos]=='1'){
        sz+=restore(pos+2,dep-1,toadd);
    }
    c[sz-1+toadd]=dep;
    if(s[pos+1]=='1'){
        sz+=restore(2*sz+pos,dep-1,toadd+sz);
    }
    return sz;
}
 
vector<int> ans;
vector<int> solve_queries(int subtask_id,int N,const string &bits,const vector<int> &a,const vector<int> &b){
    s=bits;
    restore(0,N,0);
    //for(int i=0;i<N;i++)cout<<c[i]<<" ";
 
    calc();
    for(int i=0;i<N;i++)vv.push_back(c[i]);
    for(int i=0;i<a.size();i++){
        ans.push_back(mins(a[i],b[i]));
    }
    return ans;
}
 
 
/*
int main(){
    vector<int> w;
    read_array(0,{5,6,1,8,7,4,10,3,2,9} );
 
    solve_queries(0,10,s,{0, 0, 0, 0, 1, 1, 1, 2, 2, 3} , {0, 1, 2, 3, 1, 2, 3, 2, 3, 3 });
    //for(int i=0;i<w.size();i++)cout<<w[i]<<" ";
}
*/

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0;i<v.size();i++)vv.push_back(v[i]);
      |                 ~^~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     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 3 ms 1612 KB Output is correct
2 Correct 4 ms 1400 KB Output is correct
3 Correct 3 ms 1416 KB Output is correct
4 Correct 2 ms 1428 KB Output is correct
5 Correct 2 ms 1448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 6344 KB Output is correct
2 Correct 32 ms 6108 KB Output is correct
3 Correct 27 ms 6152 KB Output is correct
4 Correct 26 ms 6448 KB Output is correct
5 Correct 26 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 21512 KB Output is correct
2 Correct 129 ms 21504 KB Output is correct
3 Correct 115 ms 21600 KB Output is correct
4 Correct 127 ms 22244 KB Output is correct
5 Correct 119 ms 21488 KB Output is correct