結果

問題 No.2574 Defect-free Rectangles
ユーザー MagentorMagentor
提出日時 2023-11-13 17:28:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,643 bytes
コンパイル時間 3,158 ms
コンパイル使用メモリ 266,656 KB
実行使用メモリ 45,460 KB
最終ジャッジ日時 2023-11-26 18:51:01
合計ジャッジ時間 7,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 6 ms
6,676 KB
testcase_04 AC 6 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 331 ms
7,552 KB
testcase_07 AC 291 ms
7,552 KB
testcase_08 AC 285 ms
7,552 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (int i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
const int MOD = 998244353LL;

ll solve(vector<int> &w){
set<int> st;
vector<pair<ll,ll>> v(w.size());
rep(i,w.size()){v[i] = pair(w[i],i);}
sort(l(v));
st.insert(-1);
int n = w.size();
st.insert(n);
ll ans = 0;
rep(i,n){
  auto t = st.lower_bound(v[i].second);
  auto k = t;k--;
  ans += (v[i].second-(ll)(*k)) * ((ll)(*t)-v[i].second) * v[i].first;
  st.insert(v[i].second);
}
return ans;
}

int main(){
  ll h,w,n;cin>>h>>w>>n;
  vector<vector<int>> v(h,vector<int>(w,0));
  rep(i,n){
  int a,b;cin>>a>>b;a--;b--;
  v[a][b] = 1;
  }
//  otp(v);
  //vector<vector<ll>> t(h,vector<ll>(w,0));
  rep(i,w){
    ll now = 0;
    rep(j,h){now++;if(v[h-j-1][i]==1){now = 0;}v[h-j-1][i] = now;}
  }
 // otp(v);
  ll ans = 0;
  rep(i,h){
   // rep(j,h){cout << w[j] << " ";}cout<<endl;
    ans += solve(v[i]);
   // cout << solve(w).val() << endl;
  }
 // vector<ll> y={2,1,3,4,5};
  //cout << solve(y) << endl;
  //cout << solveg(y) << endl;
  cout << ans << endl;
}
0