Its took me a while to come up with this. Please see if something like this helps
<pre search> | eval x = if(match(field_1,"XXX"),1,if(match(field_1,"YYY"),0,-1)) | accum x AS total_x | table _time,field_1,x,total_x | eval y = if(x=0,total_x,NULL) |filldown y | fillnull value=0 y | delta y as z | eval z = if(z=0,NULL,z) | eval w = coalesce(z,x) | eval w = if(x=0,0-w,w)| accum w as total_w
Here total_w column would be your requested re-setted accum count.
where XXX is where the we assume 1 is added and YYY is event where after the reset is required