Problem p02620 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE> void print_vec(const vector<TYPE> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
  cout << endl;
  for (int i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   " << endl;
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\\x1B[0m" << endl;
  }
}

const int D = 365;
vector<int> c(26, 0);
vector<vector<int>> s(D, vector<int>(26, 0));

ll calc_score(vector<int> &t) {
  vector<int> last(26, -1);
  ll score = 0;
  for (int d = 0; d < D; d++) {
    int type = t[d];
    score += s[d][type];
    last[type] = d;

    for (int i = 0; i < 26; i++) {
      score = score - c[i] * (d - last[i]);
    }
  }
  return score;
}

int main() {
  int tmp;
  cin >> tmp;
  // vector<int> c(26, 0);
  for (int i = 0; i < 26; i++)
    cin >> c[i];
  // vector<vector<int>> s(D, vector<int>(26, 0));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  vector<int> t(D);
  for (int i = 0; i < D; i++) {
    cin >> t[i];
    t[i]--;
  }

  ll M;
  cin >> M;
  vector<int> day(M), q(M);

  for (int i = 0; i < M; i++) {
    cin >> day[i] >> q[i];
    day[i]--;
    q[i]--;
  }

  for (int i = 0; i < M; i++) {
    t[day[i]] = q[i];
    cout << calc_score(t) << endl;
  }
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE> void print_vec(const vector<TYPE> &v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) {
  cout << endl;
  for (int i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   " << endl;
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\\x1B[0m" << endl;
  }
}

const int D = 5;
vector<int> c(26, 0);
vector<vector<int>> s(D, vector<int>(26, 0));
ll calc_score(vector<int> &t) {
  vector<int> last(26, -1);
  ll score = 0;
  for (int d = 0; d < D; d++) {
    int type = t[d];
    score += s[d][type];
    last[type] = d;

    for (int i = 0; i < 26; i++) {
      score = score - c[i] * (d - last[i]);
      // cout << " d: " << d << " i: " << i << " c[]: " << c[type] << " score: "
      // << score << endl;
    }
    // cout << " c[3]: " << c[3] << " (d - last[3]): "<< (d - last[3]) << " c[3]
    // * (d - last[3]): " << c[3] * (d - last[3]) << endl; cout << score <<
    // endl;
  }
  return score;
}

int main() {
  int tmp;
  cin >> tmp;
  // vector<int> c(26, 0);
  for (int i = 0; i < 26; i++)
    cin >> c[i];
  // vector<vector<int>> s(D, vector<int>(26, 0));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  vector<int> t(D);
  for (int i = 0; i < D; i++) {
    cin >> t[i];
    t[i]--;
  }

  ll M;
  cin >> M;
  vector<int> day(M), q(M);

  for (int i = 0; i < M; i++) {
    cin >> day[i] >> q[i];
    day[i]--;
    q[i]--;
  }

  for (int i = 0; i < M; i++) {
    t[day[i]] = q[i];
    cout << calc_score(t) << endl;
  }
}