博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gym - 101350A Sherlock Bones(思维)
阅读量:4987 次
发布时间:2019-06-12

本文共 1467 字,大约阅读时间需要 4 分钟。

The great dog detective Sherlock Bones is on the verge of a new discovery. But for this problem, he needs the help of his most trusted advisor -you- to help him fetch the answer to this case.

He is given a string of zeros and ones and length N.

Let F(x, y) equal to the number of ones in the string between indices x and yinclusively.

Your task is to help Sherlock Bones find the number of ways to choose indices (i, j, k) such that i < j < ksj is equal to 1, and F(i, j) is equal to F(j, k).

Input

The first line of input is T – the number of test cases.

The first line of each test case is an integer N (3 ≤ N ≤ 2 × 105).

The second line is a string of zeros and ones of length N.

Output

For each test case, output a line containing a single integer- the number of ways to choose indices (i, j, k).

Example

Input
3 5 01010 6 101001 7 1101011
Outpu2
3 7 题意: 给定01字符串,求有多少个三元组i,j,k满足i
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define fuck(x) cout<<#x<<" = "<
<
v;ll sum[maxn];int main(){ int T; scanf("%d",&T); while(T--){ int len; scanf("%d%s",&len,s); memset(sum,0,sizeof(sum)); v.clear(); ll ans=1; for(int i=0;i
=0;i--){ sum[i]=v[i]+sum[i+2]; } ans=0; for(int i=0;i
View Code

 

 

转载于:https://www.cnblogs.com/ZGQblogs/p/10661616.html

你可能感兴趣的文章
头文件包含方式
查看>>
C# 日志系统 log4net 配置及使用
查看>>
JavaScript获取当前url路径
查看>>
Python_正则(re.math()的简单说明)
查看>>
Base64编码简介
查看>>
边缘检测———拟合圆
查看>>
通过剪切板传递数据—— 传递一个对象
查看>>
[React Native] Reusable components with required propType
查看>>
[Ramada] Build a Functional Pipeline with Ramda.js
查看>>
[Express] Level 4: Body-parser -- Delete
查看>>
c++模板分离式编译时无法解析外部符号
查看>>
SQL Server 2008 收缩日志 删除日志
查看>>
telnet命令 测试端口连接是否正常
查看>>
数据库 sharding
查看>>
Java中long和Long有什么区别 (转载)
查看>>
HDU4336 Card Collector(期望 状压 MinMax容斥)
查看>>
P2590 [ZJOI2008]树的统计
查看>>
09:矩阵乘法
查看>>
【第一周】进度条
查看>>
Hibernate 异常:“@OneToOne or @ManyToOne on XXX references an unknown entity: XXX”
查看>>