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

【题意】

题意

【题解】

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

【代码】

  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N = 2e5;
  5. int n;
  6. ll t;
  7. ll a[N+10];
  8. ll b[N*2+10];
  9. map<ll,int> dic,dic1;
  10. int lowbit(int x){
  11. return x&(-x);
  12. }
  13. ll get_sum(int x){
  14. ll ans = 0;
  15. while (x>0){
  16. ans = ans + b[x];
  17. x = x-lowbit(x);
  18. }
  19. return ans;
  20. }
  21. void add(int x){
  22. while (x<=2*N+2){
  23. b[x]= b[x]+1;
  24. x = x + lowbit(x);
  25. }
  26. }
  27. int main(){
  28. ios::sync_with_stdio(0),cin.tie(0);
  29. cin >> n >> t;
  30. dic[0] = 1;
  31. dic[0+t] = 1;
  32. for (int i = 1;i <= n;i++) {
  33. cin >> a[i];
  34. a[i]+=a[i-1];
  35. dic[a[i]] = 1;
  36. dic[a[i]+t] = 1;
  37. }
  38. int cnt = 0;
  39. for (auto temp:dic){
  40. cnt++;
  41. dic1[temp.first] = cnt;
  42. }
  43. add(dic1[0+t]);
  44. //cout<<dic1[0+t]<<endl;
  45. ll fans = 0;
  46. for (int i = 1;i <= n;i++){
  47. ll temp1 = get_sum(cnt)-get_sum(dic1[a[i]]);
  48. fans = fans + temp1;
  49. add(dic1[a[i]+t]);
  50. }
  51. cout<<fans<<endl;
  52. return 0;
  53. }

【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. java-异常简介

    1.简介 ############################################################### ############################### ...

  2. 用WEKA进行数据挖掘

    学习于IBM教学文档 数据挖掘学习与weka使用 第二部 分分类和集群 分类 vs. 群集 vs. 最近邻 在我深入探讨每种方法的细节并通过 WEKA 使用它们之前,我想我们应该先理解每个模型 - 每 ...

  3. How many Fibs? POJ - 2413

    How many Fibs? POJ - 2413 高精模板 #include<cstdio> #include<cstring> #include<algorithm& ...

  4. 题解报告:hdu 1176 免费馅饼(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小 ...

  5. fastboot命令详解

    Android手机分区(每个分区都有相应的img文件对应):开机启动画面区(splash1),数据恢复区(recovery),内核区(boot), 系统区(system),数据缓存区(cache),用 ...

  6. NSSet转成NSArray 以及NSSortDescriptor的使用

    //如果想排序以后再取,可以这样:NSSet *users = [groupUser users]; //如果是存的字典,则key后面写的是想按照哪个关键字进行排序 NSSortDescriptor ...

  7. [转]Resolve Team Foundation Version Control conflicts

    本文转自:http://msdn.microsoft.com/en-us/library/ms181432.aspx An advantage of using Team Foundation ver ...

  8. Spring Cloud是什么?

    [学习笔记] 3)Spring Cloud是什么?马克-to-win@马克java社区:i)Spring Cloud是一个微服务框架,Spring Cloud基于微服务基础框架Netflix进行了up ...

  9. P1062 数列

    题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,13,… (该序列实际上就是 ...

  10. QT入门学习

    第一个QT程序 #include<QApplication> #include<QDialog> #include<QLabel> #include<QTex ...