Language: C++

#include<bits/stdc++.h>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

inline void chkmin(int &a,int b){if(a>b)a=b;}
inline void minn(int a,int b){if(a<b)return a;return b;}

const int N=5009;
const int Q=200009;
const int Inf=1e9+7;

struct node
{
	int l,r;
}qu[Q];

int n,q,ans;
int b[N],sum[N];
int f[N];
vector<int> g[N];

inline int zero(int l,int r)
{
	return r-(l-1)-(sum[r]-sum[l-1]);
}

inline int one(int l,int r)
{
	if(l>r)return 0;
	return sum[r]-sum[l-1];
}

#define mid ((l+r)>>1)

inline void upd(int z)
{
	t[z]=minn(t[z<<1],t[z<<1|1]);
}

inline void build(int x,int l,int r)
{
	if(l==r)
	{
		t[x]=(f[l]=Inf)-sum[l];
		return;
	}
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	upd(x);
}

inline void modify(int x,int l,int r,int p)
{
	if(l==r)
	{
		t[x]=f[l]-sum[l];
		return;
	}
	if(p<=mid)
		modify(x<<1,l,mid,p);
	else 
		modify(x<<1|1,mid+1,r,p);
	upd(x);
}

inline int query(int x,int l,int r,int dl,int dr)
{
	if(dl==l && r==dr)
		return t[x];
	if(dr<=mid)
		return query(x<<1,l,mid,dl,dr);
	else if(mid<dl)
		return query(x<<1|1,mid+1,r,dl,dr);
	return minn(query(x<<1,l,mid,dl,mid),query(x<<1|1,mid+1,r,mid+1,dr));
}

int main()
{
	if(fopen("hamming.in","r"))
	{
		freopen("hamming.in","r",stdin);
		freopen("hamming.out","w",stdout);
	}

	n=read();
	for(int i=1;i<=n;i++)
	{
		b[i]=read()^1;
		sum[i]=sum[i-1]+b[i]^1;
	}
	q=read();
	for(int i=1;i<=q;i++)
	{
		qu[i].l=read(),qu[i].r=read();
		g[qu[i].l-1].push_back(r);
	}
	
	build(1,0,n);
	f[0]=0;
	for(int i=0;i<n;i++)//pos
	{
		for(int j=0;j<g[i].size();j++)
		{
			chkmin(f[g[i][j]],query(1,0,n,i,g[i][j]-1)+sum[g[i][j]]);
			modify(1,0,n,g[i][j]);
		}
		chkmin(f[i+1],f[i]+b[i]^1);
		modify(1,0,n,i+1);
	}

	printf("%d\n",f[n]);
	return 0;
}



Compiler output:
a.cc: In function 'void minn(int, int)':
a.cc:14:45: error: return-statement with a value, in function returning 'void' [-fpermissive]
   14 | inline void minn(int a,int b){if(a<b)return a;return b;}
      |                                             ^
a.cc:14:54: error: return-statement with a value, in function returning 'void' [-fpermissive]
   14 | inline void minn(int a,int b){if(a<b)return a;return b;}
      |                                                      ^
a.cc: In function 'void upd(int)':
a.cc:45:9: error: 't' was not declared in this scope
   45 |         t[z]=minn(t[z<<1],t[z<<1|1]);
      |         ^
a.cc: In function 'void build(int, int, int)':
a.cc:52:17: error: 't' was not declared in this scope
   52 |                 t[x]=(f[l]=Inf)-sum[l];
      |                 ^
a.cc: In function 'void modify(int, int, int, int)':
a.cc:64:17: error: 't' was not declared in this scope
   64 |                 t[x]=f[l]-sum[l];
      |                 ^
a.cc: In function 'int query(int, int, int, int, int)':
a.cc:77:24: error: 't' was not declared in this scope
   77 |                 return t[x];
      |                        ^
a.cc:82:20: error: void value not ignored as it ought to be
   82 |         return minn(query(x<<1,l,mid,dl,mid),query(x<<1|1,mid+1,r,mid+1,dr));
      |                ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:103:40: error: 'r' was not declared in this scope
  103 |                 g[qu[i].l-1].push_back(r);
      |                                        ^