#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[40005][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) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
812 KB |
Output is correct |
2 |
Correct |
2 ms |
808 KB |
Output is correct |
3 |
Correct |
1 ms |
804 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
1068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
5000 KB |
Output is correct |
2 |
Correct |
18 ms |
4748 KB |
Output is correct |
3 |
Correct |
18 ms |
5000 KB |
Output is correct |
4 |
Correct |
18 ms |
4916 KB |
Output is correct |
5 |
Correct |
20 ms |
4764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
11392 KB |
Output is correct |
2 |
Correct |
82 ms |
15060 KB |
Output is correct |
3 |
Correct |
75 ms |
14968 KB |
Output is correct |
4 |
Correct |
72 ms |
14856 KB |
Output is correct |
5 |
Correct |
72 ms |
14952 KB |
Output is correct |