二次联通门 : LibreOJ #6220. sum
/* LibreOJ #6220. sum 对所有数做一个前缀和 如果某一位模N等于另一位 则他们中间的一段的和一定为N的倍数 自己感悟一下 (MMP 我交了11遍才过!!!!⑨快把我冻成冰块!!) */ #include <cstdio> #include <iostream> #define Max 1111111 int pos[Max]; typedef long long LL; inline void read (LL &now) { register char c = getchar (); for (now = 0; !isdigit (c); c = getchar ()); for (; isdigit (c); now = now * 10 + c - '0', c = getchar ()); } LL a[Max]; int Main () { int N; int s = 0; scanf ("%d", &N); register int i; for (i = 1, pos[0] = 1; i <= N; ++ i) { read (a[i]); s = (s + a[i]) % N; if (!pos[s]) pos[s] = i + 1; else { for (register int j = pos[s]; j <= i; ++ j) printf ("%d %lld ", j, a[j]); return 0; } } return 0; } int ZlycerQan = Main (); int main (int argc, char *argv[]) {;}