#include <bits/stdc++.h>
#include "floppy.h"
using namespace std;
int n;
string bits;
void read_array(int subtask_id, const vector<int> &v)
{
n = (int)v.size();
stack<int> s;
for(int i = 0; i < n; i++)
{
while(!s.empty() && v[i] > s.top())
bits.push_back('1'), s.pop();
bits.push_back('0');
s.push(v[i]);
}
save_to_floppy(bits);
return;
}
int blift[20005][20];
int qry(int x, int y)
{
int rez = y;
for(int j = 19; j >= 0; j--)
if(blift[rez][j] >= x)
rez = blift[rez][j];
return rez;
}
vector<int> solve_queries(int subtask_id, int n, const string &bit, const vector<int> &a, const vector<int> &b)
{
bits = bit;
int cnt = 0;
stack<int> s;
for(int i = 0; i < n; i++)
{
while(bits[cnt] == '1')
s.pop(), cnt++;
if(!s.empty())
blift[i + 1][0] = s.top() + 1;
s.push(i), cnt++;
}
for(int j = 1; j <= 19; j++)
for(int i = 1; i <= n; i++)
blift[i][j] = blift[blift[i][j - 1]][j - 1];
/*for(int j = 0; j <= 3; j++)
{
cout<<j<<":\n";
for(int i = 1; i <= n; i++)
cout<<blift[i][j]<<" ";
cout<<'\n';
}*/
vector<int> rez;
for(int i = 0; i < a.size(); i++)
{
int x = a[i], y = b[i];
rez.push_back(qry(x + 1, y + 1) - 1);
cout<<rez[i]<<" ";
}
return rez;
}
/*int main()
{
vector<int> __a = {40, 20, 30, 10};
//read_array(1, __a);
solve_queries(1, 4, "00100", {0, 0, 0, 0, 1, 1, 1, 2, 2, 3}, {0, 1, 2, 3, 1, 2, 3, 2, 3, 3 });
return 0;
}*/
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:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | 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) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
828 KB |
Security error -- do not print anything to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
4220 KB |
Security error -- do not print anything to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
67 ms |
15640 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |