【Codeforces 1042D】Petya and Array
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
把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的更多相关文章
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 258B】 Sort the Array
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
- 【codeforces 719E】Sasha and Array
[题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...
- 【44.19%】【codeforces 727C】Guess the Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 1114B】Yet Another Array Partitioning Task
[链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...
- 【Codeforces 111C】Petya and Spiders
Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- java-异常简介
1.简介 ############################################################### ############################### ...
- 用WEKA进行数据挖掘
学习于IBM教学文档 数据挖掘学习与weka使用 第二部 分分类和集群 分类 vs. 群集 vs. 最近邻 在我深入探讨每种方法的细节并通过 WEKA 使用它们之前,我想我们应该先理解每个模型 - 每 ...
- How many Fibs? POJ - 2413
How many Fibs? POJ - 2413 高精模板 #include<cstdio> #include<cstring> #include<algorithm& ...
- 题解报告:hdu 1176 免费馅饼(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小 ...
- fastboot命令详解
Android手机分区(每个分区都有相应的img文件对应):开机启动画面区(splash1),数据恢复区(recovery),内核区(boot), 系统区(system),数据缓存区(cache),用 ...
- NSSet转成NSArray 以及NSSortDescriptor的使用
//如果想排序以后再取,可以这样:NSSet *users = [groupUser users]; //如果是存的字典,则key后面写的是想按照哪个关键字进行排序 NSSortDescriptor ...
- [转]Resolve Team Foundation Version Control conflicts
本文转自:http://msdn.microsoft.com/en-us/library/ms181432.aspx An advantage of using Team Foundation ver ...
- Spring Cloud是什么?
[学习笔记] 3)Spring Cloud是什么?马克-to-win@马克java社区:i)Spring Cloud是一个微服务框架,Spring Cloud基于微服务基础框架Netflix进行了up ...
- P1062 数列
题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,13,… (该序列实际上就是 ...
- QT入门学习
第一个QT程序 #include<QApplication> #include<QDialog> #include<QLabel> #include<QTex ...