Submission #1063565

# Submission time Handle Problem Language Result Execution time Memory
1063565 2024-08-17T20:37:01 Z MarwenElarbi Radio Towers (IOI22_towers) C++17
17 / 100
694 ms 5584 KB
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
#define pb push_back
#define ll long long
#define fi first
#define se second
const int nax=1e5+5;
int lefty[nax],righty[nax];
int segtree[nax*4];
int n;
vector<int> tab;
int pre[nax];
vector<int> ans;
void build(int pos,int l,int r){
  if(l==r){
    segtree[pos]=tab[l];
    return;
  }
  int mid=(r+l)/2;
  build(pos*2+1,l,mid);
  build(pos*2+2,mid+1,r);
  segtree[pos]=max(segtree[pos*2+1],segtree[pos*2+2]);
  return;
}
int query(int pos,int l,int r,int left,int right){
  if(l>r||l>right||r<left) return -1;
  if(l>=left&&r<=right) return segtree[pos];
  int mid=(r+l)/2;
  return max(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
void init(int N, std::vector<int> H) {
  n=N;
  for (int i = 0; i < N; ++i)
  {
    tab.pb(H[i]);
  }
  stack<pair<int,int>> st;
  for (int i = 0; i < n; ++i)
  {
    while(!st.empty()){
      if(st.top().fi>tab[i]){
        st.pop();
      }else break;
    }
    lefty[i]=(!st.empty() ? st.top().se : -1);
    st.push({tab[i],i});
  }
  while(!st.empty()) st.pop();
  for (int i = n-1; i >= 0; --i)
  {
    while(!st.empty()){
      if(st.top().fi>tab[i]){
        st.pop();
      }else break;
    }
    righty[i]=(!st.empty() ? st.top().se : n);
    st.push({tab[i],i});
  }
  build(0,0,n-1);
  for (int i = 0; i < n; ++i)
  {
    int a=query(0,0,n-1,lefty[i]+1,i-1);
    int b=query(0,0,n-1,i+1,righty[i]-1);
    if(lefty[i]==-1) a=2e9;
    if(righty[i]==n) b=2e9;
    ans.pb(min(a,b)-tab[i]);
  }
  sort(ans.begin(),ans.end());
}

int max_towers(int L, int R, int D){
  int l=-1;
  int r=ans.size();
  while(r-l>1){
    int mid=(r+l)/2;
    if(ans[mid]<D) l=mid;
    else r=mid;
  }
  return max((int)ans.size()-r,1);
}
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 4052 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 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 502 ms 4816 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 198 ms 3080 KB Output is correct
2 Correct 694 ms 4816 KB Output is correct
3 Correct 676 ms 4816 KB Output is correct
4 Correct 642 ms 4808 KB Output is correct
5 Correct 689 ms 4808 KB Output is correct
6 Correct 642 ms 4816 KB Output is correct
7 Correct 649 ms 4928 KB Output is correct
8 Correct 658 ms 5308 KB Output is correct
9 Correct 659 ms 5576 KB Output is correct
10 Correct 636 ms 5072 KB Output is correct
11 Correct 644 ms 5124 KB Output is correct
12 Correct 39 ms 4816 KB Output is correct
13 Correct 38 ms 4808 KB Output is correct
14 Correct 38 ms 4816 KB Output is correct
15 Correct 33 ms 5576 KB Output is correct
16 Correct 38 ms 5072 KB Output is correct
17 Correct 49 ms 4808 KB Output is correct
18 Correct 40 ms 4688 KB Output is correct
19 Correct 38 ms 4808 KB Output is correct
20 Correct 38 ms 4884 KB Output is correct
21 Correct 38 ms 4816 KB Output is correct
22 Correct 37 ms 4816 KB Output is correct
23 Correct 39 ms 4816 KB Output is correct
24 Correct 38 ms 5320 KB Output is correct
25 Correct 31 ms 5572 KB Output is correct
26 Correct 37 ms 5064 KB Output is correct
27 Correct 37 ms 5584 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 2 ms 2392 KB Output is correct
42 Correct 2 ms 2392 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 4052 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -