【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

把a[i]处理成前缀和
离散化.
枚举i从1..n假设a[i]是区间和的a[r]
显然我们需要找到a[r]-a[l]

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 2e5; int n;
ll t;
ll a[N+10];
ll b[N*2+10];
map<ll,int> dic,dic1; int lowbit(int x){
return x&(-x);
} ll get_sum(int x){
ll ans = 0;
while (x>0){
ans = ans + b[x];
x = x-lowbit(x);
}
return ans;
} void add(int x){
while (x<=2*N+2){
b[x]= b[x]+1;
x = x + lowbit(x);
}
} int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> t;
dic[0] = 1;
dic[0+t] = 1;
for (int i = 1;i <= n;i++) {
cin >> a[i];
a[i]+=a[i-1];
dic[a[i]] = 1;
dic[a[i]+t] = 1;
}
int cnt = 0;
for (auto temp:dic){
cnt++;
dic1[temp.first] = cnt;
}
add(dic1[0+t]);
//cout<<dic1[0+t]<<endl;
ll fans = 0;
for (int i = 1;i <= n;i++){
ll temp1 = get_sum(cnt)-get_sum(dic1[a[i]]);
fans = fans + temp1;
add(dic1[a[i]+t]);
}
cout<<fans<<endl;
return 0;
}

【Codeforces 1042D】Petya and Array的更多相关文章

  1. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

  4. 【codeforces 719E】Sasha and Array

    [题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...

  5. 【44.19%】【codeforces 727C】Guess the Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【Codeforces 1114B】Yet Another Array Partitioning Task

    [链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...

  7. 【Codeforces 111C】Petya and Spiders

    Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. [POI2009]Kon

    Description 火车沿途有N个车站,告诉你从每一站到每一站的人数,现在查票员只能查K次票,每次查票可以控制目前在车上的所有乘客的车票.求一个查票方案,使得控制的不同的乘客尽量多. (显然对同一 ...

  2. 【洛谷3343_BZOJ3925】[ZJOI2015]地震后的幻想乡(状压 DP_期望)

    题目: 洛谷 3343 BZOJ 3925 分析: 谁给我说这是个期望概率神题的,明明没太大关系好吧 「提示」里那个结论哪天想起来再问 Jumpmelon 怎么证. 首先,由于开始修路前 \(e_i\ ...

  3. Visual studio docker build no such file or directory

    在我构建新的镜像的时候, 发生 了  no such file or directory 的错误.  这个错误找了半天, 没头绪,项目结构是这样的: WebApplication1 建立在根目录下,是 ...

  4. 科普 eclipse中的Java build

    在刚学eclipse的时候,build path是经常会用到的,但经常就是跟着教程走,额就不太懂这是干嘛的,然后今天看见极客视频里有相关的讲解,来记录一下. Build Path 是指定Java工程所 ...

  5. 【深入.NET平台】浅谈.NET Framework基元类型

    什么是基元类型? 初学者可能很少听说过这个名词,但是平时用得最多的肯定是基元类型.先看下面两行代码: System.Int32 a = ; ;  上面两行代码都表示声明一个int类型的变量,但在平时写 ...

  6. c#拖拽文件

    在“属性”窗口中,先设置MDI的父窗口的AllowDrop 属性更改为true;2.在父窗口的事件中添加下面两个事件 private void Form1_DragEnter(object sende ...

  7. java数据结构和算法04(链表)

    前面我们看了数组,栈和队列,大概就会这些数据结构有了一些基本的认识,首先回顾一下之前的东西: 在数组中,其实是分为有序数组和无序数组,我简单实现了无序数组,为什么呢?因为有序数组的实现就是将无序数组进 ...

  8. web.xml 加载顺序

    参考网址: 上下文对象>监听>过滤器>servlet 1.先加载上下文对象 <!-- 初始化Spring classpath*:spring/applicationContex ...

  9. 数组(Arry)几个常用方法的详解

    join() 方法用于把数组中的所有元素放入一个字符串.元素是通过指定的分隔符进行分隔的. arrayObject.join(separator)separator 可选.指定要使用的分隔符.如果省略 ...

  10. leetcode_1011. Capacity To Ship Packages Within D Days_binary search二分

    https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 传送带每天有最大传送量V,对于n个货物[w1,w2,w3. ...