QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#17359. 旋转工艺

الإحصائيات

旋转工艺

  • 时间限制:$1$ 秒
  • 空间限制:$512\text{ MB}$

题目描述

给定长度为 $n$ 的整数序列 $a$ 和整数 $k$,$a$ 序列下标从 $1$ 开始。

记 $a$ 的第 $t$ 个循环移位($0 \le t < n$)为序列 $b$,其中:

$$ b_i = a_{((i+t-1)\bmod n)+1} $$

定义 $b$ 的前缀和为:

$$ s_i = \sum_{j=1}^{i} b_j $$

求满足“存在 $i \in [1,n]$ 使得 $s_i = k$”的循环移位 $t$ 的个数。

输入格式

本题包含多组测试数据。

输入第一行输入两个非负整数 $c,t$ 分别表示测试点所在的子任务编号和测试数据组数,其中样例满足 $c = 0$。

接下来依次输入每组测试数据,对于每组测试数据:

  • 第一行包含两个正整数 $n,k$,表示序列的长度以及要求出现的整数。
  • 第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$ 表示序列。

输出格式

对于每组测试数据,输出一行一个非负整数表示你的答案。

样例输入

0 10
2 4
2 2
4 2
1 1 -1 -1
1 0
1
2 -1
-2 -1
3 0
-2 -1 3
4 -2
1 -3 -2 -1
5 -3
-4 0 -5 1 5
6 -4
5 2 -1 3 -6 -3
7 -7
2 7 -5 -2 7 -1 -5
8 -3
-3 5 -5 4 -7 2 -2 -7

样例输出

2
1
0
1
3
2
5
2
1
3

样例解释

对于第一组测试数据,序列 $a$ 循环移位后只能形成 $2,2$,其前缀和序列含有数字 $4$,故有 $2$ 个循环移位的序列的前缀和序列存在 $4$ 这个数字。

对于第二组测试数据,序列 $a$ 循环移位后可以形成:

  • $1,1,-1,-1$,其前缀和序列存在 $2$ 这个数字。
  • $-1,1,1,-1$,其前缀和序列不存在 $2$ 这个数字。
  • $-1,-1,1,1$,其前缀和序列不存在 $2$ 这个数字。
  • $1,-1,-1,1$,其前缀和序列不存在 $2$ 这个数字。

故只有 $1$ 种循环移位的方案其前缀和序列存在 $2$ 这个数字。

数据规模与约定

本题使用捆绑测试。 各个子任务对应的特殊数据范围如下:

  • Subtask 1(20 分):$\sum n \leq 2000$;
  • Subtask 2(15 分):$\sum n \leq 2 \times 10^5$,$a_i \ge 0$;
  • Subtask 3(15 分):$\sum n \leq 2 \times 10^5, k=0$;
  • Subtask 4(15 分):$\sum n \leq 2 \times 10^5$,$|a_i| \leq 1$;
  • Subtask 5(15 分):$\sum n \leq 2 \times 10^5$,对于任意 $1 \le i \le n-2$,满足 $a_i = a_{i+2}$。
  • Subtask 6(10 分):$\sum n \leq 2 \times 10^5$;
  • Subtask 7(10 分):无特殊性质。

对于所有数据,满足 $1 \le t \le 10^6$,$1 \le n,\sum n \le 10^6$,$-10^9 \le a_i \le 10^9$,$-10^{15} \le k \le 10^{15}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.