#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define pb push_back
#define lim 300000
#define till 40001
// # of primes till 1e6 = 7e4
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
using pii = array<int,2>;
const int mod=1000000007ll;
struct comp{
bool operator() (pii a,pii b){
if(a[1]-a[0]>b[1]-b[0]){
return 0;
}
if(a[1]-a[0]<b[1]-b[0]){
return 1;
}
return a[0]>b[0];
}
};
void solve(){
int n,m,q;
cin>>m>>n>>q;
int a[n];
int lad[min(m,300000ll)];
for(int i=0;i<n;i++){
cin>>a[i];
lad[i]=a[i];
}
sort(a,a+n);
priority_queue<pii,vector<pii>,comp>all;
if(a[0]!=1)all.push({1,a[0]-1});
for(int i=0;i<n-1;i++){
//cerr<<a[i]+1<<" "<<a[i+1]-1<<"\n";
if(a[i]+1<=a[i+1]-1)all.push({a[i]+1,a[i+1]-1});
}
if(a[n-1]+1<=m)all.push({a[n-1]+1,m});
int next=n;
while(all.size()&&next<min(m,300000ll)){
pii cur=all.top();
all.pop();
int mid;
if((cur[1]-cur[0])%2)mid=(cur[1]+cur[0])/2;
else mid=(cur[1]+cur[0])/2;
//if(next<100)cerr<<cur[0]<<" "<<mid<<" "<<cur[1]<<"\n";
lad[next++]=mid;
if(cur[0]<=mid-1)all.push({cur[0],mid-1});
if(cur[1]>=mid+1)all.push({mid+1,cur[1]});
}
/*
for(int i=0;i<m;i++){
cerr<<lad[i]<<" ";
}cerr<<"\n";
*/
for(int i=0;i<q;i++){
int tem;
cin>>tem;
tem--;
cout<<lad[tem]<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
#ifndef INTERACTIVE
freopen("in","r",stdin);
#endif
freopen("out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
2520 KB |
Output is correct |
4 |
Correct |
27 ms |
2516 KB |
Output is correct |
5 |
Correct |
46 ms |
6100 KB |
Output is correct |
6 |
Correct |
47 ms |
6084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11972 KB |
Output is correct |
2 |
Correct |
44 ms |
11204 KB |
Output is correct |
3 |
Correct |
56 ms |
13512 KB |
Output is correct |
4 |
Correct |
62 ms |
12932 KB |
Output is correct |
5 |
Correct |
65 ms |
13504 KB |
Output is correct |
6 |
Correct |
62 ms |
13764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
53 ms |
18620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |