企业建站划算吗,宁波网站建设服务商,承德网络推广,天津河北做网站的公司排名传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给定一个长度为nnn的序列aaa#xff0c;定义一段区间为好区间是这段区间的所有连续子区间的和都不为000#xff0c;求好区间的个数。
思路#xff1a;
套路题#xff0c;定义aia_iai的前缀和bi∑j1i…传送门
文章目录题意思路题意
给定一个长度为nnn的序列aaa定义一段区间为好区间是这段区间的所有连续子区间的和都不为000求好区间的个数。
思路
套路题定义aia_iai的前缀和bi∑j1iaib_i\sum _{j1}^ia_ibi∑j1iai一段区间(l,r](l,r](l,r]合法当且仅当不存在l1i,j≤rl1 i,j \le rl1i,j≤r且bibjb_ib_jbibj。所以我们对于每个bib_ibi求前面与他相等的相距最近的位置last[i]last[i]last[i]之后我们就可以枚举右端点rrr了lll的话对rrr以及前面的位置lastlastlast取一个maxmaxmax即可这样就可以保证(l,r](l,r](l,r]中没有相等的bbb我们让答案加上其长度即可。
// Problem: C. Eugene and an array
// Contest: Codeforces - Codeforces Round #632 (Div. 2)
// URL: https://codeforces.com/contest/1333/problem/C
// Memory Limit: 256 MB
// Time Limit: 1500 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includeassert.h
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].ltr[u].r1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N1000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n;
int a[N],last[N];
mapLL,intmp;int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);cinn;for(int i1;in;i) scanf(%d,a[i]);LL ans0,pre0;for(int i0;in;i) {prea[i];if(!mp.count(pre)) last[i]-1,mp[pre]i;else last[i]mp[pre],mp[pre]i;}int l-1;for(int i1;in;i) {lmax(l,last[i]);ansi-l-1;}coutansendl;return 0;
}
/**/