# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28190 | 2017-07-15T14:30:24 Z | samir_droubi | OGLEDALA (COI15_ogledala) | C++14 | 2533 ms | 297808 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; const int mxn=(1e5)+5; ll m; int n,q; ll a[mxn]; struct seg{ ll len; int i; ll sz; }; bool cmp(seg x,seg y) { if(x.len==y.len)return x.i<y.i; return x.len>y.len; } vector<seg>v; map<ll,ll>cnt; void divide(ll ln,int i) { cnt.clear(); ++cnt[ln]; while(!cnt.empty()) { map<ll,ll>::iterator it=cnt.end(); --it; ll len=it->first; ll sz=it->second; seg tmp; tmp.len=len; tmp.sz=sz; tmp.i=i; v.push_back(tmp); if(len>1) { if(len%2) cnt[len/2]+=sz*2; else { cnt[len/2]+=sz; if(len/2 != 1)cnt[len/2 - 1]+=sz; } } cnt.erase(it); } } map<ll,ll>dis; void dfs(ll v) { if(v==1)return; if(dis.count(v/2)==0) { dis[v/2]=0; dfs(v/2); } if(v%2==0) { if(v/2==1)return; if(dis.count(v/2 - 1)==0) { dis[v/2 - 1]=0; dfs(v/2 - 1); } } } ll query(ll ln,ll x,int i) { dis.clear(); ll l=a[i-1]+1; ll r=a[i]-1; dfs(r-l+1); dis[ln]=1; map<ll,ll>::iterator it=dis.begin(); for(it;it!=dis.end();++it) { ll len=it->first; ll sz=it->second; if(dis.count(len*2))dis[len*2]+=sz; if(dis.count(len*2 + 1))dis[len*2 + 1]+=sz*2; if(dis.count(len*2 + 2))dis[len*2 + 2]+=sz; } while(l<=r) { ll md=(l+r)/2; if(r-l+1==ln)return md; ll vl=dis[md-l]; if(vl<x) { x-=vl; l=md+1; } else r=md-1; } return 0; } int main() { scanf("%lld%d%d",&m,&n,&q); for(int i=1;i<=n;++i) scanf("%lld",&a[i]); a[n+1]=m+1; for(int i=1;i<=n+1;++i) { if(a[i-1]+1<=a[i]-1) divide(a[i]-a[i-1]-1,i); } sort(v.begin(),v.end(),cmp); int it=-1; ll sm=0; for(int i=0;i<q;++i) { ll x; scanf("%lld",&x); if(x<=n) { printf("%lld\n",a[x]); continue; } else x-=n; while(sm<x&&it+1<v.size()) { ++it; sm+=v[it].sz; v[it].sz=sm; } ll vl=0; if(i>0)vl=v[it-1].sz; printf("%lld\n",query(v[it].len,x-vl,v[it].i)); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2812 KB | Output is correct |
2 | Correct | 0 ms | 2812 KB | Output is correct |
3 | Correct | 69 ms | 5200 KB | Output is correct |
4 | Correct | 79 ms | 5200 KB | Output is correct |
5 | Correct | 109 ms | 12112 KB | Output is correct |
6 | Correct | 116 ms | 12112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 39 ms | 3180 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1726 ms | 150352 KB | Output is correct |
2 | Correct | 1686 ms | 150352 KB | Output is correct |
3 | Incorrect | 2533 ms | 297808 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |