# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
634937 | danikoynov | Floppy (RMI20_floppy) | C++14 | 457 ms | 15164 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "floppy.h"
using namespace std;
const int maxn = 40010;
void save_to_floppy(const string &);
void read_array(int subtask_id, vector < int > const&v)
{
stack < int > st;
st.push(0);
string bit = "";
for (int i = 1; i < v.size(); i ++)
{
while(!st.empty() && v[st.top()] < v[i])
{
bit = bit + "0";
st.pop();
}
st.push(i);
bit = bit + "1";
}
save_to_floppy(bit);
}
vector < pair < int, int > > g[maxn];
int par[maxn];
int find_leader(int v)
{
if (v == par[v])
return v;
return find_leader(par[v]);
}
void unite(int v, int u)
{
v = find_leader(v);
u = find_leader(u);
if (v < u)
swap(v, u);
par[u] = v;
}
vector < int > ans;
vector < int > solve_queries(int subtask_id, int N, const string &bits,
const vector < int > &a,
const vector < int > &b)
{
for (int i = 0; i < N; i ++)
par[i] = i;
int m = a.size();
ans.resize(m);
for (int i = 0; i < m; i ++)
{
g[b[i]].push_back({a[i], i});
}
stack < int > st;
st.push(0);
int idx = 0;
for (pair < int, int > p : g[0])
{
ans[p.second] = find_leader(p.first);
}
for (int i = 1; i < N; i ++)
{
while(bits[idx] != '1')
{
unite(st.top(), i);
st.pop();
idx ++;
}
st.push(i);
idx ++;
for (pair < int, int > p : g[i])
{
ans[p.second] = find_leader(p.first);
///cout << p.second << " : " << find_leader(p.first) << " " << p.first << " " << i << endl;
}
}
/**for (int i = 0; i < m; i ++)
cout << ans[i] << " ";
cout << endl;*/
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |