Cod sursa(job #1391328)

Utilizator alevasluialeHuhurez Marius alevasluiale Data 17 martie 2015 20:41:51
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.93 kb
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
using namespace std;
bitset<200001>lin,col;
struct pas
{
    int nr,x1,x2;
};
struct comp
{
    bool operator () (const pas &zem,const pas &cem)
    {
        return zem.nr<cem.nr;
    }
};
priority_queue<pas,vector<pas> , comp>H1;
priority_queue<pas,vector<pas> , comp>H2;
int main()
{
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    pas A,B;
    int n,m,k,i,p,ok,j;
    char NER;
    scanf("%d %d %d\n",&n,&m,&k);
    A.nr=m;
    A.x1=0;
    A.x2=m;
    H1.push(A);
    A.nr=n;A.x1=0;A.x2=n;
    H2.push(A);
    for(i=1;i<=k;i++)
    {
        scanf("%c %d\n",&NER,&p);
        if(NER=='H') lin[p]=1;
        else col[p]=1;
        A=H1.top();
        ok=1;
        while(ok)
        {
            ok=0;
            for(j=A.x1;j<=A.x2;j++)
            {
                if(lin[j]==1)
                {
                    ok=1;
                    B.nr=j-A.x1;
                    B.x1=A.x1;
                    B.x2=j;
                    H1.push(B);
                    B.nr=A.x2-j;
                    B.x1=j;
                    B.x2=A.x2;
                    H1.push(B);
                    H1.pop();
                    break;
                }
            }
        }
        A=H2.top();
        ok=1;
        while(ok)
        {
            ok=0;
            for(j=A.x1;j<=A.x2;j++)
            {
                if(col[j]==1)
                {
                    ok=1;
                    B.nr=j-A.x1;
                    B.x1=A.x1;
                    B.x2=j;
                    H2.push(B);
                    B.nr=A.x2-j;
                    B.x1=j;
                    B.x2=A.x2;
                    H2.push(B);
                    H2.pop();
                    break;
                }
            }
        }
        printf("%d\n",H1.top().nr*H2.top().nr);
    }
}