528A - Glass Carving - CodeForces Solution


data structures implementation *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
long long m, n, q, x;
char ch;
multiset<long long> s, t, l, r;
int main() {
	scanf("%d%d%d", &n, &m, &q);
	s.insert(-n), l.insert(0), l.insert(n);
	t.insert(-m), r.insert(0), r.insert(m);
	for (int i = 1; i <= q; ++i) {
		scanf("\n%c %d", &ch, &x);
		int left, right;
		if (ch == 'H') {
			auto it = r.upper_bound(m - x);
			right = *it, left = *(--it);
			t.erase(t.lower_bound(-(right - left)));
			t.insert(-(m - x - left));
			t.insert(-(right - m + x));
			r.insert(m - x);
		} else {
			auto it = l.upper_bound(x);
			right = *it, left = *(--it);
			s.erase(s.lower_bound(-(right - left)));
			s.insert(-(right - x));
			s.insert(-(x - left));
			l.insert(x);
		}
		printf("%lld\n", (*s.begin()) * (*t.begin()));
	}
	return 0;
}
	   	 	  		  						 							   	
	  		  		  	   		 		 	  	  	 	


Comments

Submit
0 Comments
More Questions

1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB