Language: C++

//#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

ifstream cin ("x.in"); ofstream cout ("x.out");

const int nmax = 3000;
const int mod = 1e9 + 7;

int n, m;
int s[nmax + 1];
int d[nmax + 1][nmax + 1];

pair<int, int> w[nmax + 1];
vector< pair<int, int> > unu;

string vs;
int v[nmax + 1];

inline bool cmpdr (int x) {
    return x == 0;
}

inline bool cmpst (int x) {
    return x > 0;
}

void precalc() {
    unu.push_back(make_pair(0, 0));
    for (int i = 0; i < n; ++ i) {
        if (vs[ i ] == '1') {
            v[i + 1] = unu.size();
            unu.push_back(make_pair(0, 0));
        }
    }

    for (int i = 1; i <= m; ++ i) {
        stable_partition(v + w[ i ].first, v + w[ i ].second + 1, cmpdr);
    }

    for (int i = 1; i <= n; ++ i) {
        if (v[ i ]) {
            unu[ v[ i ] ].second = i;
        }
    }

    int shp = 0;
    for (int i = 0; i < n; ++ i) {
        if (vs[ i ] == '1') {
            v[i + 1] = ++ shp;
        } else {
            v[i + 1] = 0;
        }
    }

    for (int i = 1; i <= m; ++ i) {
        stable_partition(v + w[ i ].first, v + w[ i ].second + 1, cmpst);
    }

    for (int i = 1; i <= n; ++ i) {
        if (v[ i ]) {
            unu[ v[ i ] ].first = i;
        }
    }
}

int main() {
    cin >> n >> m >> vs;

    for (int i = 1; i <= m; ++ i) {
        int x, y;
        cin >> x >> y;
        w[ i ] = make_pair(x, y);
    }

    precalc();

    d[ 0 ][ 0 ] = 1;
    for (int i = 0; i <= n; ++ i) s[ i ] = 1;

    for (int i = 1; i < (int)unu.size(); ++ i) {
        for (int j = unu[ i ].first; j <= unu[ i ].second; ++ j) {
            d[ i ][ j ] = s[j - 1];
        }

        s[ 0 ] = 0;
        for (int j = 1; j <= n; ++ j) {
            s[ j ] = s[j - 1] + d[ i ][ j ];
            if (s[ j ] >= mod) {
                s[ j ] -= mod;
            }
        }
    }

    cout << s[ n ] << "\n";

    return 0;
}


Compiler output:
a.cc:9:14: error: variable 'std::ifstream cin' has initializer but incomplete type
    9 | ifstream cin ("x.in"); ofstream cout ("x.out");
      |              ^
a.cc:6:1: note: 'std::ifstream' is defined in header '<fstream>'; this is probably fixable by adding '#include <fstream>'
    5 | #include <algorithm>
  +++ |+#include <fstream>
    6 | 
a.cc:9:38: error: variable 'std::ofstream cout' has initializer but incomplete type
    9 | ifstream cin ("x.in"); ofstream cout ("x.out");
      |                                      ^
a.cc:9:38: note: 'std::ofstream' is defined in header '<fstream>'; this is probably fixable by adding '#include <fstream>'
a.cc: In function 'int main()':
a.cc:72:5: error: reference to 'cin' is ambiguous
   72 |     cin >> n >> m >> vs;
      |     ^~~
In file included from a.cc:2:
/usr/include/c++/14/iostream:62:18: note: candidates are: 'std::istream std::cin'
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:9:10: note:                 '<typeprefixerror>cin'
    9 | ifstream cin ("x.in"); ofstream cout ("x.out");
      |          ^~~
a.cc:76:9: error: reference to 'cin' is ambiguous
   76 |         cin >> x >> y;
      |         ^~~
/usr/include/c++/14/iostream:62:18: note: candidates are: 'std::istream std::cin'
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:9:10: note:                 '<typeprefixerror>cin'
    9 | ifstream cin ("x.in"); ofstream cout ("x.out");
      |          ^~~
a.cc:99:5: error: reference to 'cout' is ambiguous
   99 |     cout << s[ n ] << "\n";
      |     ^~~~
/usr/include/c++/14/iostream:63:18: note: candidates are: 'std::ostream std::cout'
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:9:33: note:                 '<typeprefixerror>cout'
    9 | ifstream cin ("x.in"); ofstream cout ("x.out");
      |                                 ^~~~