#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 1000
//para el vector de querys
#define p second.first
#define id second.second
lli n,q,apu,a,b,t,pos;
lli arr[2][MAX+2];
vector<pair<lli,pll > > querys;
vector<lli> res;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
res.resize(q+2);
rep(i,1,n) cin >> arr[apu][i];
rep(i,1,q) {
cin >> a >> b;
if (a > n) a = n;
querys.push_back({a,{b,i}});
}
sort(querys.begin(), querys.end());
pos = 0;
t = 0;
while (pos < querys.size()) {
while (pos < querys.size() && querys[pos].first == t) {
res[querys[pos].id] = arr[apu][ querys[pos].p ];
pos++;
}
if (pos >= querys.size()) break;
//shuffle
lli a = 1;
lli b = (n/2)+1;
lli otro = (apu^1);
lli cont = 1;
rep(i,1,n) {
if (a > n/2) {
arr[otro][cont++] = arr[apu][b];
b++;
}
if (b > n) {
arr[otro][cont++] = arr[apu][a];
a++;
}
//escojo el menor entre los 2
lli soy;
if (arr[apu][a] < arr[apu][b]) soy = a++;
else soy = b++;
arr[otro][cont++] = arr[apu][soy];
}
apu = otro;
t++;
}
rep(i,1,q) cout << res[i] << "\n";
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:39:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while (pos < querys.size()) {
| ~~~~^~~~~~~~~~~~~~~
Main.cpp:40:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while (pos < querys.size() && querys[pos].first == t) {
| ~~~~^~~~~~~~~~~~~~~
Main.cpp:44:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | if (pos >= querys.size()) break;
| ~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
35872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
16468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
35872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |