#ifndef call_from_test #include using namespace std; using Int = long long; #endif //BEGIN CUT HERE template struct SparseTable{ using F = function; vector< vector > dat; vector ht; const F f; SparseTable(){} SparseTable(F f):f(f){} void build(const vector &v){ int n=v.size(),h=1; while((1<(n)); ht.assign(n+1,0); for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1; for(int j=0;j a(n); for(int i=0;i st(f); st.build(a); map ans; for(int i=0;i>1; if(st.query(i,m)!=pre) r=m; else l=m; } ans[pre]+=l-pl; pre=st.query(i,r); } ans[lst]+=n-l; } printf("%lld\n",ans[1]); return 0; } /* verified on 2019/11/11 https://atcoder.jp/contests/arc023/tasks/arc023_4 */ signed main(){ ARC023_D(); return 0; } #endif