Language: C++

#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=3e5+100;
const int MOD=1000000007;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n,m;
char s[twx];
int l[twx],r[twx];
int ans=0;
int one[twx];
int asd[twx][twx];
int To[twx];
ll add(ll x,ll y)
{
    return x+y>=MOD?x+y-MOD:x+y;
}
ll sub(ll x,ll y)
{
    return x-y<0?x-y+MOD:x-y;
}
ll mul(ll x,ll y)
{
    return 1LL*x*y%MOD;
}
void init()
{
	n=read();
    m=read();
    scanf("%s",s+1);
    f1(1,n,i)
    {
        if(s[i]=='1')
        {
            one[i]=one[i-1]+1;
        }
        else
        {
            one[i]=one[i-1];
        }
        To[i]=i;
    }
    one[n+1]=one[n];
    f1(1,m,i)
    {
        l[i]=read();
        r[i]=read();
        To[l[i]]=max(To[l[i]],r[i]);
    }
    f1(2,n+1,i)
    {
        To[i]=max(To[i],To[i-1]);
    }
}
void work()
{
    asd[1][one[To[1]]]=1;
    f1(1,n,i)
    {
        f1(0,n,j)
        {
            if(asd[i][j])
            {
                int Left=To[i]+1;
                int Right=To[i+1];
                int tmp=one[Right]-one[Left-1];
                int a=j;
                int b=To[i]-i+1-a;
                if(a)
                {
                    asd[i+1][j+tmp-1]=add(asd[i+1][j+tmp-1],asd[i][j]);
                }
                if(b)
                {
                    asd[i+1][j+tmp]=add(asd[i+1][j+tmp],asd[i][j]);
                }
            }
        }
    }
}
void print()
{
	printf("%d\n",asd[n+1][0]);
}
int main()
{
    init();
    work();
    print();
	return 0;
}

Compiler output:
/tmp/ccd2mm1S.o: in function `init()':
a.cc:(.text+0x218): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x2f0): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x32a): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x360): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x377): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x39c): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
/tmp/ccd2mm1S.o: in function `work()':
a.cc:(.text+0x3c3): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x450): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x470): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
a.cc:(.text+0x4c6): relocation truncated to fit: R_X86_64_PC32 against symbol `To' defined in .bss section in /tmp/ccd2mm1S.o
collect2: error: ld returned 1 exit status