Problem p03037 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \
  if (false)                                                                   \
  cout
#define debug() if (false)
#define check(x)                                                               \
  if (false)                                                                   \
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \
  if (false)                                                                   \
  cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N, M;
  int L, R;
  int ans = 0;
  cin >> N >> M;
  vector<int> list(N);
  rep(i, M) {
    cin >> L >> R;
    rep(i, L - 1) { list[i] = 1; }
    for (int i = R; i < N; i++) {
      list[i] = 1;
    }
    dout << "====listの内容====\n";
    for (int i = 0; i < N; i++)
      dout << list[i] << endl;
    dout << "====ここまで====\n";
  }
  rep(i, N) {
    if (list[i] == 0) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/

Fixed submission:
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \
  if (false)                                                                   \
  cout
#define debug() if (false)
#define check(x)                                                               \
  if (false)                                                                   \
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \
  if (false)                                                                   \
  cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N, M;
  int L, R;
  int ans = 0;
  cin >> N >> M;
  vector<int> list(N);
  rep(i, M) {
    cin >> L >> R;
    if (list[L - 2] == 0) {
      rep(i, L - 1) { list[i] = 1; }
    }
    if (list[R] == 0) {
      for (int i = R; i < N; i++) {
        list[i] = 1;
      }
    }
    dout << "====listの内容====\n";
    for (int i = 0; i < N; i++)
      dout << list[i] << endl;
    dout << "====ここまで====\n";
  }
  rep(i, N) {
    if (list[i] == 0) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/