Submission #27596

#TimeUsernameProblemLanguageResultExecution timeMemory
27596khsoo01OGLEDALA (COI15_ogledala)C++11
41 / 100
4000 ms107884 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 100005; ll l, a[N], qry[N]; int n, m, cur[N]; vector<ll> v[N], dt[N]; priority_queue<pair<ll, int> > pq; int geti (vector<ll> &V, int I, ll P) { for(int i=max(0,I-3);i<I;i++) if(V[i] == P) return i; return -1; } void add (vector<ll> &V, ll A) { if(A <= 0 || geti(V, V.size(), A) != -1) return; V.push_back(A); } void kth (int I, int C, int O, ll S, ll E, ll K) { if(C == O) {printf("%lld\n",(S+E)/2); return;} ll L = E-S+1; int I1 = geti(v[I], C, (L-1)/2), I2 = (L/2 == (L-1)/2 ? I1 : I1+1); if(I1>=O && dt[I][I1] >= K) kth(I, I1, O, S, (S+E)/2-1, K); else kth(I, I2, O, (S+E)/2+1, E, K - (I1>=O ? dt[I][I1] : 0)); } void calc (vector<ll> &D, vector<ll> &V, int O) { for(int i=0;i<O;i++) D[i] = 0; D[O] = 1; for(int i=O+1;i<V.size();i++) { int I1 = geti(V, i, (V[i]-1)/2), I2 = (V[i]/2 == (V[i]-1)/2 ? I1 : I1+1); D[i] = (I1 != -1 ? D[I1] : 0) + (I2 != -1 ? D[I2] : 0); } } int main() { scanf("%lld%d%d",&l,&n,&m); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); a[n+1] = l+1; for(int i=1;i<=n+1;i++) { add(v[i], a[i]-a[i-1]-1); for(ll j=0;j<v[i].size();j++) { add(v[i], v[i][j]/2); add(v[i], (v[i][j]-1)/2); } reverse(v[i].begin(), v[i].end()); } for(int i=1;i<=n+1;i++) { cur[i] = v[i].size(); dt[i].resize(v[i].size()); if(--cur[i] >= 0) { calc(dt[i], v[i], cur[i]); pq.push({v[i][cur[i]], -i}); } } int cq = 1; ll dn = n; for(int i=1;i<=m;i++) { scanf("%lld",&qry[i]); if(qry[i] <= n) { printf("%lld\n",a[qry[i]]); cq++; } } while(!pq.empty()) { int C = -pq.top().second; ll V = dt[C][v[C].size()-1]; pq.pop(); for(;cq <= m && qry[cq] <= dn + V; cq++) { kth(C, v[C].size()-1, cur[C], a[C-1]+1, a[C]-1, qry[cq]-dn); } if(cq > m) break; dn += V; if(--cur[C] >= 0) { calc(dt[C], v[C], cur[C]); pq.push({v[C][cur[C]], -C}); } } }

Compilation message (stderr)

ogledala.cpp: In function 'void calc(std::vector<long long int>&, std::vector<long long int>&, int)':
ogledala.cpp:34:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=O+1;i<V.size();i++) {
                 ^
ogledala.cpp: In function 'int main()':
ogledala.cpp:46:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll j=0;j<v[i].size();j++) {
               ^
ogledala.cpp:41:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%d%d",&l,&n,&m);
                            ^
ogledala.cpp:42:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
                                           ^
ogledala.cpp:62:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&qry[i]);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...