File size: 1,617 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()

{
    ll t;
    cin >> t;
    while(t--) {
        ll n, m, q, line, state, px, py, nx, ny, mx, mxd, mxx;
        scanf("%lld %lld %lld", &n, &m, &q);
        set <ll> x, y;
        multiset <ll> dif, difx;

        set <ll> :: iterator it1, it2;
        multiset <ll> :: iterator it3;

        x.insert(0), x.insert(n);
        y.insert(0), y.insert(m);
        dif.insert(m);
        difx.insert(n);

        for(ll i = 1; i <= q; i++) {
            scanf("%lld %lld", &state, &line);
            if(state == 0) {
                if( x.find(line) == x.end()) {

                    it3 = x.lower_bound(line);
                    px = *(--it3);

                    it3 = x.upper_bound(line);
                    nx = *it3;

                    difx.erase( difx.find(nx - px) );
                    difx.insert(line - px);
                    difx.insert(nx - line);
                    x.insert(line);
                }
            }
            else if(y.find(line) == y.end()) {

                it3 = y.lower_bound(line);
                py = *(--it3);

                it3 = y.upper_bound(line);
                ny = *it3;

                //cout << ny << "  " << py << "  " << line << endl;
                dif.erase( dif.find(ny - py) );
                dif.insert(line - py);
                dif.insert(ny - line);
                y.insert(line);
            }

            mxd = *(--dif.end());
            mxx = *(--difx.end());
            mx = mxd * mxx;

            printf("%lld\n", mx);
        }
    }

    return 0;
}