题目连接

看代码:

#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long LL;
using namespace std;
//const int inf=INT_MAX;
const int maxn=100000+100;
//#include <bits/stdc++.h>
int a[maxn];
int p1[maxn];
int main ()
{
int n;
while(~scanf("%d",&n))
{
memset(p1,0,sizeof(p1));
int sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum%3)
printf("0\n");
else
{
LL ans=0;
int key=sum/3;
int sum1=0;
int sum2=0;
for(int i=n;i>=1;i--)
{
sum2+=a[i];
if(sum2==key)
p1[i-1]=p1[i]+1;
else
p1[i-1]=p1[i];
}
for(int i=1;i<=n;i++)
{
sum1+=a[i];
if(sum1==key)
{
ans+=p1[i+1];
}
}
printf("%lld\n",ans);
}
}
return 0;
}

cddiv/数组维护的更多相关文章

  1. [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)

    树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...

  2. HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gc ...

  3. POJ 3321 Apple Tree(后根遍历将树转化成序列,用树状数组维护)

    题意:一棵树,有很多分叉,每个分叉上最多有1个苹果. 给出n,接下来n-1行,每行u,v,表示分叉u,v之间有树枝相连.这里数据中u相当于树中的父节点,v相当于子节点. 给出两个操作: 1.C x  ...

  4. 第十二届湖南省赛G - Parenthesis (树状数组维护)

    Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...

  5. LOJ107. 维护全序集【树状数组维护全序集】

    题目描述 这是一道模板题,其数据比「普通平衡树」更强. 如未特别说明,以下所有数据均为整数. 维护一个多重集 S ,初始为空,有以下几种操作: 把 x 加入 S 删除 S 中的一个 x,保证删除的 x ...

  6. 【BZOJ2124】等差子序列 树状数组维护hash值

    [BZOJ2124]等差子序列 Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】

    任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...

  8. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】

    题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...

  9. 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...

随机推荐

  1. stb_image读取图片数据

    #include <iostream> #include <fstream> #include <stbi/stb_image.h> const unsigned ...

  2. MVC3+EF4.1学习系列(八)-----利用Repository and Unit of Work重构项目

    项目最基础的东西已经结束了,但是现在我们的项目还不健全  不利于测试 重复性代码多   层与层之间耦合性高  不利于扩展等问题.今天的这章 主要就是解决这些问题的.再解决这些问题时,自己也产生了很多疑 ...

  3. VC中获取窗口控件相对客户区的坐标

    1: RECT rect; 2: GetDlgItem(item_id).GetWindowRect(&rect); 3: ScreenToClient(&rect);

  4. 第二次冲刺spring会议(第六次会议)

    [例会时间]2014/5/8 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳 奇

  5. 洛谷-陶陶摘苹果(升级版)-BOSS战-入门综合练习1

    题目描述 Description 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他手够不着时,他会站到椅子上再试试. 这次与NOIp2005普及组第一题不同 ...

  6. python-连接数据库

    from sqlalchemy import create_engine,text,Column,Integer,String,Sequencefrom sqlalchemy.ext.declarat ...

  7. HDU--1301--Jungle Roads(最小生成树)

    Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of for ...

  8. Vim 配置Markdown

    通过vundle工具安装以下插件: vim-markdown   语法高亮 vim-markdown-preview.vim  通过浏览器实时预览(支持同步滚动) -/.vimrc vundle部分添 ...

  9. # Linux Whois3获取 运营商信息

    Linux Whois3获取 运营商信息 APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的,并提供了一个查询工具,下面就让我们看看如何在Linux ...

  10. 高效程序猿之 VS2010快速生成代码模板

    本文转载,原文地址 http://edi.wang/Post/2011/12/8/efficient-code-monkey-1-vs2010-generate-code-template 一只程序猿 ...