結果

問題 No.2574 Defect-free Rectangles
ユーザー Taiki0715Taiki0715
提出日時 2023-12-03 11:48:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,632 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 158,776 KB
実行使用メモリ 53,132 KB
最終ジャッジ日時 2023-12-03 11:48:14
合計ジャッジ時間 11,412 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 131 ms
20,212 KB
testcase_07 AC 181 ms
20,212 KB
testcase_08 AC 179 ms
20,212 KB
testcase_09 AC 1,632 ms
53,132 KB
testcase_10 AC 1,382 ms
53,132 KB
testcase_11 AC 1,597 ms
53,132 KB
testcase_12 AC 1,568 ms
53,132 KB
testcase_13 AC 883 ms
53,132 KB
testcase_14 AC 440 ms
28,404 KB
testcase_15 AC 172 ms
18,164 KB
testcase_16 AC 39 ms
11,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
constexpr int MAX=4096,LOG=12;
int lazy[MAX*2];
int dat[MAX*2];
int a[MAX][MAX];
inline void update(int i){dat[i]=dat[i*2]+dat[i*2+1];}
inline void push(int i){
  if(lazy[i]!=-2){
    lazy[i*2]=lazy[i*2+1]=lazy[i];
    dat[i*2]=dat[i*2+1]=lazy[i]<<(__builtin_clz(i)+LOG-32);
    lazy[i]=-2;
  }
}
int prod(int r){
  r+=MAX;
  int l=MAX;
  int ret=0;
  for(int i=LOG;i>=1;i--)if(((r>>i)<<i)!=r)push((r-1)>>i);
  while(l<r){
    if(l&1)ret+=dat[l++];
    if(r&1)ret+=dat[--r];
    l>>=1;
    r>>=1;
  }
  return ret;
}
void apply(int l,int f){
  l+=MAX;
  int r=MAX*2;
  for(int i=LOG;i>=1;i--)if(((l>>i)<<i)!=l)push(l>>i);
  int l2=l,r2=r;
  while(l<r){
    if(l&1){
      dat[l]=f<<(__builtin_clz(l)+LOG-31);
      lazy[l++]=f;
    }
    if(r&1){
      r--;
      dat[r]=f<<(__builtin_clz(r)+LOG-31);
      lazy[r]=f;
    }
    l>>=1,r>>=1;
  }
  l=l2,r=r2;
  for(int i=1;i<=LOG;i++){
    if(((l>>i)<<i)!=l)update(l>>i);
  }
}
int read_int() {
    int ret = 0;
    char ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return ret;
}
int main(){
  int h,w,n,x,y;
  h=read_int(),w=read_int(),n=read_int();
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)a[i][j]=-1;
  while(n--){
    x=read_int(),y=read_int();
    a[x-1][y-1]=0;
  }
  for(int i=h;i--;)for(int j=0;j<w;j++)if(a[i][j]==-1){
    if(i==h)a[i][j]=1;
    else a[i][j]=a[i+1][j]+1;
  }
  for(int i=1;i<MAX*2;i++)lazy[i]=-2;
  long long ans=0;
  for(int i=0;i<h;i++){
    lazy[1]=-1;
    dat[1]=-MAX;
    for(int j=0;j<w;j++){
      ans+=j*a[i][j]-prod(a[i][j]);
      apply(a[i][j],j);
    }
  }
  cout<<ans<<endl;
}
0