Problem p01110 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MAX_N 100
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w, h, t, p, d, c;
  while (cin >> w >> h >> t >> p, w | h | t | p) {
    int table[MAX_N + 10][MAX_N + 10] = {};
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        table[i][j] = 1;
    for (int i = 0; i < t; i++) {
      cin >> d >> c;
      if (d == 1) {
        for (int j = 0; j < h; j++) {
          for (int k = 0; k < c; k++) {
            int alpha = c - k - 1;
            table[j][c + alpha] += table[j][k];
            table[j][k] = 0;
          }
        }
        for (int j = 0; j < MAX_N; j++) {
          for (int k = 0; k < MAX_N; k++) {
            table[j][k] = table[j][k + c];
          }
        }
      } else if (d == 2) {
        for (int j = 0; j < c; j++) {
          for (int k = 0; k < w; k++) {
            int alpha = c - j - 1;
            table[c + alpha][k] += table[j][k];
            table[j][k] = 0;
          }
        }
        for (int j = 0; j < MAX_N; j++) {
          for (int k = 0; k < MAX_N; k++) {
            table[j][k] = table[j + c][k];
          }
        }
      }
    }
    int x, y;
    for (int i = 0; i < p; i++) {
      cin >> x >> y;
      cout << table[y][x] << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MAX_N 100
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w, h, t, p, d, c;
  while (cin >> w >> h >> t >> p, w | h | t | p) {
    int table[2 * MAX_N][2 * MAX_N] = {};
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        table[i][j] = 1;
    for (int i = 0; i < t; i++) {
      cin >> d >> c;
      if (d == 1) {
        for (int j = 0; j < h; j++) {
          for (int k = 0; k < c; k++) {
            int alpha = c - k - 1;
            table[j][c + alpha] += table[j][k];
            table[j][k] = 0;
          }
        }
        for (int j = 0; j < MAX_N; j++) {
          for (int k = 0; k < MAX_N; k++) {
            table[j][k] = table[j][k + c];
          }
        }
      } else if (d == 2) {
        for (int j = 0; j < c; j++) {
          for (int k = 0; k < w; k++) {
            int alpha = c - j - 1;
            table[c + alpha][k] += table[j][k];
            table[j][k] = 0;
          }
        }
        for (int j = 0; j < MAX_N; j++) {
          for (int k = 0; k < MAX_N; k++) {
            table[j][k] = table[j + c][k];
          }
        }
      }
    }
    int x, y;
    for (int i = 0; i < p; i++) {
      cin >> x >> y;
      cout << table[y][x] << endl;
    }
  }
  return 0;
}