Language: C++

#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define INF 1e7
using namespace std;

vector<int> index;

int w,n;
int val[2][1<<18];
void init(){
	n=1;
	while(n<w)n*=2;
	for(int i=0;i<2*n-1;i++)val[0][i]=val[1][i]=INF;
}

void update(int k,int a){
	k+=n-1;
	val[0][k]=a-(k-(n-1));
	val[1][k]=a-(w-1-(k-(n-1)));
	while(k>0){
		k=(k-1)/2;
		val[0][k]=min(val[0][k*2+1],val[0][k*2+2]);
		val[1][k]=min(val[1][k*2+1],val[1][k*2+2]);
	}
}

int query(int d,int a,int b,int k=0,int l=0,int r=n){
	if(a<=l && r<=b)return val[d][k];
	if(r<=a || b<=l)return INF;
	int vl=query(d,a,b,k*2+1,l,(l+r)/2);
	int vr=query(d,a,b,k*2+2,(l+r)/2,r);
	return min(vl,vr);
}

int a[100001];

int main(void){
	scanf("%d",&w);
	init();
	index.push_back(-1);
	for(int i=0;i<w;i++){
		scanf("%d",&a[i]);
		if(a[i]==0)index.push_back(i);
		if(a[i]<0){
			update(i,-a[i]);
		}
	}
	index.push_back(w);
	int cnt=0;
	for(int i=0;i<w;i++){
		if(a[i]>0){
			int num=0;
			int ld=lower_bound(index.begin(),index.end(),i)-index.begin();
			ld--;
			int dat1=-INF,dat2=-INF;
			if(ld!=0){
				dat1=query(1,index[ld]+1,i);
				if(dat1>=-(w-1-i))num=max(num,min(dat1+(w-1-i),a[i]));
			}
			int rd=lower_bound(index.begin(),index.end(),i)-index.begin();
			if(rd!=index.size()-1){
				dat2=query(0,i+1,index[rd]);
				if(dat2>=-i)num=max(num,min(dat2+i,a[i]));
			}
			cnt+=num;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Compiler output:
a.cc:8:13: error: 'std::vector<int> index' redeclared as different kind of entity
    8 | vector<int> index;
      |             ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:2:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:42:15: error: overloaded function with no contextual type information
   42 |         index.push_back(-1);
      |               ^~~~~~~~~
a.cc:45:34: error: overloaded function with no contextual type information
   45 |                 if(a[i]==0)index.push_back(i);
      |                                  ^~~~~~~~~
a.cc:50:15: error: overloaded function with no contextual type information
   50 |         index.push_back(w);
      |               ^~~~~~~~~
a.cc:55:50: error: overloaded function with no contextual type information
   55 |                         int ld=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                  ^~~~~
a.cc:55:64: error: overloaded function with no contextual type information
   55 |                         int ld=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                                ^~~
a.cc:55:79: error: overloaded function with no contextual type information
   55 |                         int ld=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                                               ^~~~~
a.cc:59:51: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   59 |                                 dat1=query(1,index[ld]+1,i);
      |                                                   ^
a.cc:62:50: error: overloaded function with no contextual type information
   62 |                         int rd=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                  ^~~~~
a.cc:62:64: error: overloaded function with no contextual type information
   62 |                         int rd=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                                ^~~
a.cc:62:79: error: overloaded function with no contextual type information
   62 |                         int rd=lower_bound(index.begin(),index.end(),i)-index.begin();
      |                                                                               ^~~~~
a.cc:63:38: error: overloaded function with no contextual type information
   63 |                         if(rd!=index.size()-1){
      |                                      ^~~~
a.cc:64:55: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   64 |                                 dat2=query(0,i+1,index[rd]);
      |                                                       ^