#include
#include
#include
using namespace std;
const int N = 5e6 + 10;
int n;
int s[N];
char str[N];
int main()
{
int T;
scanf("%d", &T);
for (int x = 1; x <= T; x ++ )
{
scanf("%d", &n);
scanf("%s", str + 1);
memset(s, 0, sizeof s);
for (int i = 1; i <= n; i ++ )
s[i] += s[i - 1] + str[i] - '0';
int k = (n - 1) / 2 + 1;
int sum = 0;
for (int i = k; i <= n; i ++ )
sum = max(sum, s[i] - s[i - k]);
printf("Case #%d: %d\n", x, sum);
}
return 0;
}
#include
#include
#include
using namespace std;
const int N = 1e5 + 10;
int n, m;
int s[N];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &s[i]);
s[i] += s[i - 1];
}
while (m -- )
{
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", s[r] - s[l - 1]);
}
return 0;
}
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int N = 100010;
int n, k;
LL s[N], cnt[N];
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &s[i]);
s[i] += s[i - 1];
}
// for (int i = 1; i <= n; i ++ ) printf("%d ", s[i]);
LL res = 0;
cnt[0] ++;
for (int i = 1; i <= n; i ++ )
{
res += (LL)cnt[s[i] % k];
cnt[s[i] % k] ++;
}
printf("%lld\n", res);
return 0;
}
#include
#include
#include
using namespace std;
typedef long long LL;
const int N = 510;
int n, m, k;
int s[N][N];
int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
{
scanf("%d", &s[i][j]);
s[i][j] += s[i - 1][j];
}
LL res = 0;
// 枚举上下边界
for (int i = 1; i <= n; i ++ )
for (int j = i; j <= n; j ++ )
// 双指针降低一层循环来枚举左右边界
for (int l = 1, r = 1, sum = 0; r <= m; r ++ )
{
sum += s[j][r] - s[i - 1][r];
while (sum > k)
{
sum -= s[j][l] - s[i - 1][l];
l ++;
}
res += r - l + 1;
}
printf("%lld\n", res);
return 0;
}