Cod sursa(job #2186539)

Utilizator mateicosCostescu Matei mateicos Data 25 martie 2018 18:32:05
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <cstdio>

using namespace std;

int a[3005][3005];

int main()
{
    freopen("pseudobil.in", "r", stdin);
    freopen("pseudobil.out", "w", stdout);
    int p, n, k, m, x, y, i, j, l, c;
    scanf("%d%d%d%d", &p, &n, &k, &m);
    if(p == 1){
      printf("%d", 2 * ((m - 1) / 2) * ((m - 1) / 2) + m - 1);
    }
    else{
      for(i = 0;i < k;i++){
        scanf("%d%d", &x, &y);
        a[x + y - 1][y - x + n] = 1;
      }
      for(i = 1;i < 2 * n;i++){
        for(j = 1;j < 2 * n;j++){
          a[i][j] = a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1] + a[i][j];
        }
      }
      scanf("%d", &k);
      for(i = 0;i < k;i++){
        scanf("%d%d", &x, &y);
        x += m / 2;
        c = y - m / 2;
        y += m / 2;
        l = x;
        printf("%d\n", a[x + y - 1][y - x + n] - a[x + y - 1][c - l + n - 1] - a[l + c - 2][y - x + n] + a[l + c - 2][c - l + n - 1]);
      }
    }
    return 0;
}