結果

問題 No.1008 Bench Craftsman
ユーザー beetbeet
提出日時 2020-03-06 21:44:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,504 ms / 2,000 ms
コード長 2,123 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 199,400 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-04-22 05:51:19
合計ジャッジ時間 23,706 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1,504 ms
9,728 KB
testcase_06 AC 148 ms
8,448 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 178 ms
5,376 KB
testcase_10 AC 1,194 ms
9,856 KB
testcase_11 AC 1,172 ms
9,728 KB
testcase_12 AC 1,188 ms
9,600 KB
testcase_13 AC 1,194 ms
9,728 KB
testcase_14 AC 1,138 ms
9,600 KB
testcase_15 AC 795 ms
9,600 KB
testcase_16 AC 818 ms
9,728 KB
testcase_17 AC 839 ms
9,728 KB
testcase_18 AC 819 ms
9,728 KB
testcase_19 AC 837 ms
9,728 KB
testcase_20 AC 358 ms
6,144 KB
testcase_21 AC 439 ms
6,144 KB
testcase_22 AC 927 ms
5,632 KB
testcase_23 AC 1,154 ms
6,912 KB
testcase_24 AC 1,172 ms
6,940 KB
testcase_25 AC 266 ms
8,064 KB
testcase_26 AC 203 ms
6,144 KB
testcase_27 AC 769 ms
5,504 KB
testcase_28 AC 739 ms
8,704 KB
testcase_29 AC 1,273 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename E, typename H>
struct SegmentTree{
  // using H = function<E(E,E)>;
  Int n,height;
  H h;
  E ei;
  vector<E> laz;

  SegmentTree(H h,E ei):h(h),ei(ei){}

  void init(Int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    laz.assign(2*n,ei);
  }

  inline void propagate(Int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    laz[k]=ei;
  }

  inline void thrust(Int k){
    for(Int i=height;i;i--) propagate(k>>i);
  }

  void update(Int a,Int b,E x){
    if(a>=b) return;
    thrust(a+=n);
    thrust(b+=n-1);
    for(Int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
  }

  E get_val(Int a){
    thrust(a+=n);
    return laz[a];
  }

  void set_val(Int a,E x){
    thrust(a+=n);
    laz[a]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  vector<Int> xs(m),ws(m);
  for(Int i=0;i<m;i++) cin>>xs[i]>>ws[i],xs[i]--;

  auto h=[&](Int a,Int b){return a+b;};
  SegmentTree<Int, decltype(h)> d1(h,0);
  SegmentTree<Int, decltype(h)> d2(h,0);
  auto check=
    [&](Int c)->bool{
      d1.init(n);d2.init(n);

      for(Int i=0;i<m;i++){
        Int x=xs[i];
        Int d=c?(ws[i]/c):n;
        // [l, r]
        Int l=x-d,r=x+d;
        chmax(l,0);
        chmin(r,n-1);
        d1.update(l,r+1,ws[i]);

        d1.update(l,x+1,-x*c);
        d2.update(l,x+1,+c);

        d1.update(x,r+1,+x*c);
        d2.update(x,r+1,-c);
      }

      for(Int i=0;i<n;i++)
        if(d1.get_val(i)+d2.get_val(i)*i>=as[i]) return 0;
      return 1;
    };

  const Int INF = 1e5+10;
  Int L=-1,R=INF;
  while(L+1<R){
    Int M=(L+R)>>1;
    if(check(M)) R=M;
    else L=M;
  }
  if(R==INF) R=-1;
  cout<<R<<endl;
  return 0;
}
0