結果

問題 No.2574 Defect-free Rectangles
ユーザー ゆにぽけ
提出日時 2024-01-15 11:51:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 135,128 KB
最終ジャッジ日時 2025-02-18 20:11:39
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void solve()
{
int H,W,N;
cin >> H >> W >> N;
vector<vector<int>> G(W);
for(int i = 0;i < N;i++)
{
int a,b;
cin >> a >> b;
G[--b].push_back(--a);
}
for(int j = 0;j < W;j++)
{
sort(G[j].begin(),G[j].end());
G[j].push_back(H);
}
vector<int> id(W);
long long ans = 0;
for(int i = 0;i < H;i++)
{
vector<int> A(W);
for(int j = 0;j < W;j++)
{
while(G[j][id[j]] < i) id[j]++;
A[j] = G[j][id[j]] - i;
}
vector<int> L(W),R(W);
vector<int> seen(W);
{
stack<int> S;
for(int j = 0;j < W;j++)
{
while(!S.empty() && A[S.top()] > A[j]) S.pop();
L[j] = S.empty() ? -1 : S.top();
S.push(j);
}
}
{
stack<int> S;
for(int j = W;j--;)
{
while(!S.empty() && A[S.top()] >= A[j]) S.pop();
R[j] = S.empty() ? W : S.top();
S.push(j);
}
}
for(int j = 0;j < W;j++)
{
ans += (long long) A[j] * (R[j] - j) * (j - L[j]);
}
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
/* cin >> tt; */
while(tt--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0