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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include "message.h"
#include "dzialka.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const ll INS = 100;

void updateMin(deque<pii> &D, ll time, ll llerv, ll val)
{
    while(!D.empty() && D.front().second <= time-llerv)
    {
        D.pop_front();
    }

    while(!D.empty() && D.back().first > val)
    {
        D.pop_back();
    }

    D.push_back(pii(val, time) );

    return;
}

ll fnd(ll x, ll y, ll n, ll m)
{
    vector<ll> above;
    deque<pii> minim;
    above.resize(m);



    ll res = 0;
    //cout << n << m;
    for(ll i=0; i<n; i++)
    {
        ll behindMe = 0;
        minim.clear();
        for(ll j=0; j<m; j++)
        {
            if(IsUsableCell(i, j) )
            {
                behindMe++;
                above[j]++;
                //cout << 1 << " ";
            }
            else
            {
                //cout << 0 << " ";
                behindMe = 0;
                above[j] = 0;
                // wrzuc na heap 
            }

            updateMin(minim, j, x, above[j]);

            if(behindMe >= x && minim.front().first >= y)
            {
                res++;
            }
        }
        //cout << "\n";
    }

    //cout << "\n\n";
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);

    ll n = GetFieldHeight();
    ll m = GetFieldWidth();

    
    //ll instance = MyNodeId();
    
    //<p, k)

    ll p = 1; //(n / 100) * instance;
    ll k = n;//(n / 100) * (instance + 1);

    ll res = 0;

    /*
    if(instance == INS)
    {
        k = n;
    }*/

    for(ll i=p; i<=k; i++)
    {
        for(ll j=1; j<=m; j++)
        {
            //cout << j << " " << i << "\n";
            res += fnd(j, i, n, m);
        }
    }

    /*if(instance != 0)
    {
        Putll(0, res);
        Send(0);
    }
    else
    for(ll i=1; i<100; i++)
    {
        Receive(i);
        res += Getll(i);
    }
    */

    if(MyNodeId() == 0)
    {
        cout << res << "\n";
    }
    

    return 0;
}