結果
| 問題 | No.2574 Defect-free Rectangles | 
| コンテスト | |
| ユーザー |  momoyuu | 
| 提出日時 | 2023-12-15 16:16:35 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 212 ms / 2,000 ms | 
| コード長 | 1,387 bytes | 
| コンパイル時間 | 1,257 ms | 
| コンパイル使用メモリ | 110,256 KB | 
| 実行使用メモリ | 38,656 KB | 
| 最終ジャッジ日時 | 2024-09-27 06:28:38 | 
| 合計ジャッジ時間 | 3,778 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#include<stack>
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll ans = 0;
    ll h,w,n;
    cin>>h>>w>>n;
    vector<vector<int>> a(h,vector<int>(w+1,0));
    for(int i = 0;i<n;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        a[x][y] = 1;
    }
    for(int i = 0;i<h;i++) a[i][w] = 1;
    vector<int> last(w+1,-1);
    for(int i = 0;i<h;i++){
        stack<pair<ll,ll>> st;
        for(int j = 0;j<=w;j++){
            if(a[i][j]) last[j] = i;
            int len = i - last[j];
            ll cnt = 0;
            while(st.size()){
                pair<ll,ll> now = st.top();
                if(now.first<=len) break;
                st.pop();
                ll can = now.first;
                ll mx = len;
                if(st.size()) mx = max(mx,st.top().first);
                ll use = can - mx;
                ans += use * (now.second) * (now.second+1) / 2;
                if(st.size()&&st.top().first>len){
                    st.top().second += now.second;
                    continue;
                }
                cnt += now.second;
            }
            cnt++;
            if(st.size()&&st.top().first==len) st.top().second += cnt;
            else st.push(make_pair(len,cnt));
        }
    }
    cout<<ans<<endl;
}
            
            
            
        