# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
649743 |
2022-10-11T10:03:50 Z |
daria |
Floppy (RMI20_floppy) |
C++17 |
|
112 ms |
22544 KB |
#include "bits/stdc++.h"
#include "floppy.h"
using namespace std;
const int M = (1 << 17);
int n;
string ans;
vector<string> bit(40005, "");
vector<int> adj[40005];
void dfs(int s){
ans += bit[s];
for(auto u : adj[s]) dfs(u);
}
void solve(const vector<int> &v, int l, int r, int p){
int mx = -1, id = -1;
for(int i=l; i<r; ++i)
if(v[i] > mx){ mx = v[i]; id = i;}
if(p != -1) adj[p].push_back(v[id]);
if(id == l) bit[v[id]] += '0';
else bit[v[id]] += '1';
if(id == r-1) bit[v[id]] += '0';
else bit[v[id]] += '1';
if(id != l) solve(v, l, id, v[id]);
if(id != r-1) solve(v, id+1, r, v[id]);
}
void read_array(int subtask_id, const std::vector<int> &v) {
n = v.size();
vector<pair<int, int> > v0(n);
for(int i=0; i<n; ++i) v0[i] = {v[i], i};
sort(v0.begin(), v0.end());
vector<int> v1(n);
for(int i=0; i<n; ++i) v1[v0[i].second] = i;
solve(v1, 0, n, -1);
dfs(n-1);
//cout << ans << endl;
save_to_floppy(ans);
}
vector<int> sz(40005, 1), l(40005, 0), val(40005, 0);
bool vis[40005];
int nxt = 0;
void rdfs(int id, int z, const string &st){
//cout << id << endl;
if(vis[id]) return;
vis[id] = 1;
val[id] = z;
if(st[2*id] == '1'){
l[id+1] += l[id];
//cout << "+ l padre: " << id+1 << " " << l[id+1] << endl;
rdfs(id+1, z+1, st);
sz[id] += sz[id+1];
l[id] += sz[id+1];
//cout << "+ sz figlio sx: " <<id << " " << l[id] << endl;
}
if(st[2*id+1] == '1'){
while(vis[nxt]) nxt++;
l[nxt] += l[id] + 1;
rdfs(nxt, z+1, st);
sz[id] += sz[nxt];
//cout << "+ l padre + 1: " << nxt << " " << l[nxt] << endl;
}
}
vector<pair<int, int> > st(2*M, {M, -1});
pair<int, int> query(int v, int tl, int tr, int l, int r){
if(r <= tl || tr <= l) return {M, -1};
if(l <= tl && tr <= r) return st[v];
int tm = (tl +tr)/2;
return min(query(2*v, tl, tm, l, r), query(2*v+1, tm, tr, l , r));
}
std::vector<int> solve_queries(int subtask_id,
int n,const std::string &bits,
const std::vector<int> &a, const std::vector<int> &b) {
rdfs(0, 0, bits);
vector<int> v(n);
for(int i=0; i<n; ++i) st[M+l[i]] = {val[i], l[i]};
for(int i=M-1; i>0; --i) st[i] = min(st[2*i], st[2*i+1]);
vector<int> res;
for(int i=0; i<a.size(); ++i) res.push_back(query(1, 0, M, a[i], b[i]+1).second);
//for(int i=0; i<res.size(); ++i) cout << res[i] << " ";
return res;
}
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:90:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i=0; i<a.size(); ++i) res.push_back(query(1, 0, M, a[i], b[i]+1).second);
| ~^~~~~~~~~
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) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
10176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
12872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
112 ms |
22544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |