Topic Link: Click to open the link
Test instructions
Given a matrix of n*m, K operations
2 Types of operation:
1, H x transverse in the x position cut a knife
2, V y vertical in the Y position cut a knife
Output the largest matrix area after each operation
Ideas:
Because the rows and columns are irrelevant, as long as you know the maximum spacing between each operation and the maximum spacing of the column, multiplying is the maximum area
Maintains all the coordinate points of the landscape with a set, one multiset maintains the transverse spacing.
Each pair of rows X is found in set with a minimum number of R and a size smaller than x, the maximum number of L, the space before the operation dis = r-l, delete the dis in multiset and insert r-x and x-l. Then insert X in Set
The same for column operations.
After the operation, take the maximum spacing of the rows and multiply, note that multiplying may explode int
#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <cmath > #include <cstring> #include <set> #include <map> #include <vector>using namespace std; typedef long LONG ll;const int N = 105;int heheeh;template <class t>inline BOOL Rd (T &ret) {char c; int sgn; if (c = GetChar (), c = = EOF) return 0; while (c! = '-'-' && (c< ' 0 ' | | c> ' 9 ')) C = GetChar (); SGN = (c = = '-')? -1:1; ret = (c = = '-')? 0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' &&c <= ' 9 ') ret = ret * + (C-' 0 '); RET *= SGN; return 1;} Template <class t>inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X; } if (X>9) pt (X/10); Putchar (x 10 + ' 0 ');} struct Node {int L, r, Len;}; Multiset<int> h, c;set<int> hh, Cc;set<int>::iterator it;multiset<int>::iterator ITX, Ity;int Main () {int n, m, K, X; Char a[5]; ScanF ("%d%d%d", &m, &n, &k); Hh.insert (0); Hh.insert (m); H.insert (m); Cc.insert (0); Cc.insert (n); C.insert (n); while (k--> 0) {scanf ("%s%d", A, &x); if (a[0] = = ' H ') {it = Cc.upper_bound (x); int r = *it; int l = * (--it); C.erase (C.lower_bound (r-l)); C.insert (r-x); C.insert (X-L); Cc.insert (x); } else {it = Hh.upper_bound (x); int r = *it; int l = * (--it); H.erase (H.lower_bound (r-l)); H.insert (r-x); H.insert (X-L); Hh.insert (x); } ITX = H.end (); ity = C.end (); printf ("%i64d\n", (LL) (* (--ITX)) * (* (--ity))); } return 0;}
Codeforces 528A Glass Carving STL Simulation