codeforces248(div1) B Nanami's Digital Board
q次询问,每次询问可以对矩阵某一个值改变(0变1,1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1
用up[i][j]表示(i,j)这个点向上能走到的最长高度 若(i,j)为0 则up[i][j]值为0
则每次查询时,从up[i][j]枚举至1作为子矩阵的高度,然后途中分别向左右扩展。若up[i][j - 1] >= up[i][j],则可向左扩展一个单位,答案为(r - l - 1) * 高度
同理,四个方向分别枚举
//#pragma comment(linker, "/STACK:102400000,102400000") //HEAD #include <cstdio> #include <cstring> #include <vector> #include <iostream> #include <algorithm> #include <queue> #include <string> #include <set> #include <stack> #include <map> #include <cmath> #include <cstdlib> using namespace std; //LOOP #define FE(i, a, b) for(int i = (a); i <= (b); ++i) #define FED(i, b, a) for(int i = (b); i>= (a); --i) #define REP(i, N) for(int i = 0; i < (N); ++i) #define CLR(A,value) memset(A,value,sizeof(A)) //STL #define PB push_back //INPUT #define RI(n) scanf("%d", &n) #define RII(n, m) scanf("%d%d", &n, &m) #define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k) #define RS(s) scanf("%s", s) typedef long long LL; const int INF = 0x3f3f3f3f; const int MAXN = 1010; #define FF(i, a, b) for(int i = (a); i < (b); ++i) #define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define CPY(a, b) memcpy(a, b, sizeof(a)) #define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++) #define EQ(a, b) (fabs((a) - (b)) <= 1e-10) #define ALL(c) (c).begin(), (c).end() #define SZ(V) (int)V.size() #define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p) #define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q) #define WI(n) printf("%d\n", n) #define WS(s) printf("%s\n", s) typedef vector <int> VI; typedef unsigned long long ULL; const double eps = 1e-10; const LL MOD = 1e9 + 7; const int maxn = 1010; int ipt[maxn][maxn]; int up[maxn][maxn], dwn[maxn][maxn], rht[maxn][maxn], lft[maxn][maxn]; int len[maxn], n, m; void update_col(int y) { FE(i, 1, n) if (ipt[i][y]) up[i][y] = up[i - 1][y] + 1; else up[i][y] = 0; FED(i, n, 1) if (ipt[i][y]) dwn[i][y] = dwn[i + 1][y] + 1; else dwn[i][y] = 0; } void update_row(int x) { FE(j, 1, m) if (ipt[x][j]) lft[x][j] = lft[x][j - 1] + 1; else lft[x][j] = 0; FED(j, m, 1) if (ipt[x][j]) rht[x][j] = rht[x][j + 1] + 1; else rht[x][j] = 0; } int solve(int sta, int hei, int con) { int lm = sta, rm = sta; int ans = 0; for (int h = hei; h >= 1; h--) { while (lm >= 1 && len[lm] >= h) lm--; while (rm <= con && len[rm] >= h) rm++; ans = max(ans, h * (rm - lm - 1)); } return ans; } int main() { //freopen("0.txt", "r", stdin); int q, x, y, op; cin >> n >> m >> q; FE(i, 1, n) FE(j, 1, m) RI(ipt[i][j]); FE(i, 1, n) update_row(i); FE(j, 1, m) update_col(j); while (q--) { RIII(op, x, y); if (op == 1) { ipt[x][y] ^= 1; update_row(x); update_col(y); // cout << "UP " << endl; // FE(i, 1, n) { // FE(j, 1, m) // cout << up[i][j] << ' '; // cout <<endl; // } // cout << "----" << endl; // cout << "right " << endl; // FE(i, 1, n) { // FE(j, 1, m) // cout << rht[i][j] << ' '; // cout <<endl; // } // cout << "----" << endl; } else { int ans = 0; FE(j, 1, m) len[j] = up[x][j]; ans = max(ans, solve(y, len[y], m)); FE(j, 1, m) len[j] = dwn[x][j]; ans = max(ans, solve(y, len[y], m)); FE(i, 1, n) len[i] = lft[i][y]; ans = max(ans, solve(x, len[x], n)); FE(i, 1, n) len[i] = rht[i][y]; ans = max(ans, solve(x, len[x], n)); WI(ans); } } return 0; }
以上就是codeforces248(div1) B Nanami's Digital Board的内容,更多相关内容请关注PHP中文网(www.php.cn)!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

HTML適合初學者學習,因為它簡單易學且能快速看到成果。 1)HTML的學習曲線平緩,易於上手。 2)只需掌握基本標籤即可開始創建網頁。 3)靈活性高,可與CSS和JavaScript結合使用。 4)豐富的學習資源和現代工具支持學習過程。

HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

GiteePages靜態網站部署失敗:404錯誤排查與解決在使用Gitee...

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

實現圖片點擊後周圍圖片散開並放大效果許多網頁設計中,需要實現一種交互效果:點擊某張圖片,使其周圍的...

網頁批註功能的Y軸位置自適應算法本文將探討如何實現類似Word文檔的批註功能,特別是如何處理批註之間的間�...

HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。
