【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 ...
随机推荐
- 贪心 Codeforces Round #109 (Div. 2) B. Combination
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
- Windows环境下修改Oracle实例监听IP地址
Windows环境下修改Oracle实例监听IP地址. 配置文件路径:<ORACLE_HOME>\NETWORK\ADMIN 如:C:\Oracle11gR2\product\11.2.0 ...
- 转 ORACLE-016:ora-01720 授权选项对于'xxxx'不存在
报错的情形如下, A用户:视图V_A B用户:视图V_B,并且用到了V_A C用户:需要用V_B, 授权过程, A用户下: grant select on V_A to B B用户下: grant s ...
- vue.js学习参考手册
参考手册 示例:www.51siyuan.cn/161.html
- Redux中的异步操作
异步操作的另一种方案就是让Action Creator返回一个Promise对象. 我们这边使用 redux-promise 中间件 import { createStore, applyMidd ...
- 掌握Spark机器学习库-07-最小二乘法
1)最小化残差平方和 2)原理,推导过程 3)例子
- 用16G内存在Java
用16G内存在Java Map中处理30亿对象 在一个下雨的夜晚,我在思考Java中内存管理的问题,以及Java集合对内存使用的效率情况.我做了一个简单的实验,测试在16G内存条件下,Java的Map ...
- (三)Redis for StackExchange.Redis
目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis StackExchange.Re ...
- photoshop cs6安装和破解步骤
http://tieba.baidu.com/p/4791130877 http://www.frontopen.com/1181.html
- C#通过post发送接收数据流
发送数据流方法 /// <summary> /// /// </summary> /// <param name="url">目标url< ...