Submission #782095

# Submission time Handle Problem Language Result Execution time Memory
782095 2023-07-13T15:21:40 Z FEDIKUS Radio Towers (IOI22_towers) C++17
0 / 100
571 ms 25112 KB
#include "towers.h"

#include <bits/stdc++.h>

using namespace std;

using mim = pair<pair<int,int>,int>;

const int maxn=1e5+10;
const int logg=18;

int n;
int h[maxn];
multiset<int> res;
mim sparse[logg][maxn];
int klk;
int pref[maxn];
int uniq[maxn];

mim comb(mim &a,mim &b){
  mim ret=a;
  ret.first=max(ret.first,b.first);
  ret.second=min(ret.second,b.second);
  return ret;
}

mim qry(int l,int r){
  mim ret={{h[l],l},h[l]};
  for(int i=logg-1;i>=0;i--){
    if(r-(1<<i)+1>=l){
      ret=comb(ret,sparse[i][r]);
      r-=(1<<i);
    }
  }
  return ret;
}

void resi(int l,int r,multiset<int> &ret,int naj=2e9+10){
  if(r<l) return;
  auto temp=qry(l,r);
  pair<int,int> maxi=temp.first;
  int mini=temp.second;
  multiset<int> levi; multiset<int> desni;
  resi(l,maxi.second-1,levi,maxi.first);
  resi(maxi.second+1,r,desni,maxi.first);
  if(levi.size()>desni.size()) swap(levi,desni);
  for(int i:desni) levi.emplace(i);
  if(!levi.empty()){
    auto najm=levi.begin();
    int d=naj-mini;
    if(*najm>d){
        levi.erase(najm);
        levi.emplace(d);
    }
  }else{
    levi.emplace(naj-mini);
  }
  swap(ret,levi);
}

void init(int _n, vector<int> _h) {
  n=_n;
  for(int i=0;i<n;i++) h[i]=_h[i];
  for(int i=0;i<logg;i++){
    for(int j=0;j<n;j++){
      if(i==0) sparse[i][j]={{h[j],j},h[j]};
      else if(j-(1<<(i-1))>=0) sparse[i][j]=comb(sparse[i-1][j],sparse[i-1][j-(1<<(i-1))]);
      else sparse[i][j]=sparse[i-1][j];
    }
  }
  resi(0,n-1,res);
  klk=0;
  for(int i:res) uniq[klk++]=i;
  klk=unique(uniq,uniq+klk)-uniq;
  int tren=0;
  for(int i:res){
    if(uniq[tren]!=i){
        tren++;
        pref[tren]=pref[tren-1];
    }
    pref[tren]++;
  }
}

int max_towers(int l, int r, int d) {
  int koji=upper_bound(uniq,uniq+klk,d)-uniq-1;
  if(koji==-1) return 0;
  return pref[koji];
}
# Verdict Execution time Memory Grader output
1 Incorrect 357 ms 24392 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '13', found: '20'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '13', found: '20'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 571 ms 25112 KB 1st lines differ - on the 1st token, expected: '11903', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 6480 KB 1st lines differ - on the 1st token, expected: '7197', found: '2240'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '13', found: '20'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 357 ms 24392 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -