#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int maxn=3e5+5;
class Compare{
public:
bool operator()(pair < int, int > a, pair < int, int > b){
if(a.first!=b.first){
return a.first<b.first;
}
return a.second>b.second;
}
};
bool bio[maxn];
priority_queue < pair < int, int >, vector < pair < int, int > >, Compare > svi;
int a[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m, n, q;
cin >> m >> n >> q;
for(int i=0; i<n; i++){
cin >> a[i];
a[i]--;
bio[a[i]]=1;
}
int br, pos=0;
bio[m]=1;
while(pos<m){
br=0;
while(!bio[pos]){
br++;
pos++;
}
if(br){
// cout << br << " " << pos-br << endl;
svi.push({br, pos-br});
}
pos++;
}
int val;
pos=n;
pair < int, int > p;
int b;
for(int i=0; i<q; i++){
cin >> b;
if(b<=pos){
cout << a[b-1]+1 << '\n';
continue;
}
while(pos<b){
p=svi.top();
svi.pop();
br=p.first;
// cout << "radim " << p.first << " " << p.second << endl;
val=p.second+(br-1)/2;
if(val!=p.second){
svi.push({val-p.second, p.second});
}
if(val!=p.second+br-1){
svi.push({p.second+br-1-val, val+1});
}
pos++;
}
cout << val+1 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
30 ms |
1908 KB |
Output is correct |
4 |
Correct |
28 ms |
1908 KB |
Output is correct |
5 |
Correct |
66 ms |
4080 KB |
Output is correct |
6 |
Correct |
63 ms |
4084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |