답안 #1056771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056771 2024-08-13T11:03:33 Z amirhoseinfar1385 송신탑 (IOI22_towers) C++17
0 / 100
468 ms 16720 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10,lg=18,kaf=(1<<lg),inf=1e9+5;
int all[maxn];
vector<int>allp;

struct segmentmin{
  pair<int ,int>seg[(1<<(lg+1))];
  segmentmin(){
    for(int i=2*kaf-1;i>=0;i--){
      if(i>=kaf){
        seg[i].second=i-kaf;
      }else{
        seg[i].second=seg[(i<<1)].second;
      }
    }
  }
  void ins(int i,int w){
    i+=kaf;
    seg[i].first=w;
    i>>=1;
    while(i>0){
      seg[i]=min(seg[(i<<1)],seg[(i<<1)^1]);
      i>>=1;
    }
  }
  pair<int ,int> pors(int i,int l,int r,int tl,int tr){
    if(l>r||l>tr||r<tl||tl>tr){
      return make_pair(inf,inf);
    }
    if(l>=tl&&r<=tr){
      return seg[i];
    }
    int m=(l+r)>>1;
    return min(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
  }
}segmn;

struct segmentmax{
  pair<int ,int>seg[(1<<(lg+1))];
  segmentmax(){
    for(int i=2*kaf-1;i>=0;i--){
      if(i>=kaf){
        seg[i].second=i-kaf;
      }else{
        seg[i].second=seg[(i<<1)].second;
      }
    }
  }
  void ins(int i,int w){
    i+=kaf;
    seg[i].first=w;
    i>>=1;
    while(i>0){
      seg[i]=max(seg[(i<<1)],seg[(i<<1)^1]);
      i>>=1;
    }
  }
  pair<int ,int> pors(int i,int l,int r,int tl,int tr){
    if(l>r||l>tr||r<tl||tl>tr){
      return make_pair(0,0);
    }
    if(l>=tl&&r<=tr){
      return seg[i];
    }
    int m=(l+r)>>1;
    return max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
  }
}segmx;
int n;

void build(int l,int r,int ers=inf){
  if(l==r){
    return ;
  }
  int bor=ers;
  int ind=segmx.pors(1,0,kaf-1,l,r).second;
  int cl=0,cr=0,ret=0,cnt=0;
  if(segmn.pors(1,0,kaf-1,l,ind-1).first<=all[ind]){
    int e=min(ers,all[ind]-segmn.pors(1,0,kaf-1,l,ind-1).first);
    build(l,ind-1,e);
    bor=min(bor,e);
    cnt++;
  }
  if(segmn.pors(1,0,kaf-1,ind+1,r).first<=all[ind]){
    int e=min(ers,all[ind]-segmn.pors(1,0,kaf-1,ind+1,r).first);
    build(ind+1,r,e);
    bor=min(bor,e);
    cnt++;
  }
  if(cnt==2){
    allp.push_back(bor);
  }
}

void init(int N, std::vector<int> H) {
  n=N;
  for(int i=0;i<n;i++){
    all[i]=H[i];
    segmx.ins(i,H[i]);
    segmn.ins(i,H[i]);
  }
  build(1,n);
  sort(allp.begin(),allp.end());
}


int max_towers(int L, int R, int D) {
  int p=lower_bound(allp.begin(),allp.end(),D+1)-allp.begin();
  return p;
}

Compilation message

towers.cpp: In function 'void build(int, int, int)':
towers.cpp:79:7: warning: unused variable 'cl' [-Wunused-variable]
   79 |   int cl=0,cr=0,ret=0,cnt=0;
      |       ^~
towers.cpp:79:12: warning: unused variable 'cr' [-Wunused-variable]
   79 |   int cl=0,cr=0,ret=0,cnt=0;
      |            ^~
towers.cpp:79:17: warning: unused variable 'ret' [-Wunused-variable]
   79 |   int cl=0,cr=0,ret=0,cnt=0;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 332 ms 16720 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8792 KB 1st lines differ - on the 1st token, expected: '13', found: '9'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8792 KB 1st lines differ - on the 1st token, expected: '13', found: '9'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 468 ms 10004 KB 1st lines differ - on the 1st token, expected: '11903', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 170 ms 9296 KB 1st lines differ - on the 1st token, expected: '7197', found: '807'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8792 KB 1st lines differ - on the 1st token, expected: '13', found: '9'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 332 ms 16720 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -