codeforces gym 100187M Heaviside Function
//大概就是没想起来怎么做
解法:首先观察seitan方程,发现我们要找的是满足seitan(si*x-ai)=1的方程数,即si*x-ai>=0的方程数,因为si=1 or -1,于是分类讨论,当si=1时相当于给定每个x求满足ai<=x的ai数,当si=-1时相当于给定每个x求ai<=-1的方程数,于是我们把si=1和si=-1时的系数ai分别用两个数组记录下来,然后排序,用upper_bound分别求出两种情况下的解,加起来就是答案
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#define LL long long using namespace std; int n,m;
int t1=,t2=;
int f1[],f2[]; int main(){
scanf("%d",&n);
for (int i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
if (x==)
f1[t1++]=y;
else
f2[t2++]=y;
}
sort(f1,f1+t1);
sort(f2,f2+t2);
scanf("%d",&m);
for (int i=;i<m;i++){
int x;
scanf("%d",&x);
int ans1=upper_bound(f1,f1+t1,x)-f1;
int ans2=upper_bound(f2,f2+t2,-x)-f2;
printf("%d\n",ans1+ans2);
}
return ;
}
/*
6
1 3
-1 2
1 9
-1 2
1 7
-1 2
8
0 12 2 8 4 -3 7 9
*/
codeforces gym 100187M Heaviside Function的更多相关文章
- CF Gym 100187M Heaviside Function(二分)
题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...
- Codeforces Gym 100187M M. Heaviside Function two pointer
M. Heaviside Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/ ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
随机推荐
- SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案
原文:SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Serv ...
- SVN客户端--TortoiseSVN使用说明(转)
TortoiseSVN是windows下其中一个非常优秀的SVN客户端工具.通过使用它,我们可以可视化的管理我们的版本库.不过由于它只是一个客户端,所以它不能对版本库进行权限管理. TortoiseS ...
- UESTC_Tournament CDOJ 124
A sports company is planning to advertise in a tournament. It is a single round-robin tournament, th ...
- Path Sum II 解答
Question Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the ...
- PHP MySQL Where 子句 之Where
WHERE 子句 如需选取匹配指定条件的数据,请向 SELECT 语句添加 WHERE 子句. 语法 SELECT column FROM table WHERE column operator va ...
- LDAP实例异常停止日志提示虚拟内存virtual memory不足
[05/Oct/2014:20:50:37 +0800] - ERROR<5135> - Resource Limit - conn=-1 op=-1 msgId=-1 - Memory ...
- stagefright框架(四)-Video Buffer传输流程
這篇文章將介紹Stagefright中是如何和OMX video decoder传送buffer. (1) OMXCodec會在一開始的時候透過read函式來傳送未解碼的data給decoder,並且 ...
- with ffmpeg to encode video for live streaming and for recording to files for on-demand playback
We've been doing some experimentation with ffmpeg to encode video for live streaming and for recordi ...
- jquery方法详解
jquery方法详解 http://www.365mini.com/doc
- python学习笔记:python字符串
二.python字符串操作符 1. 对象标准类型操作符 Python对象的标准类型操作符一共就三种:对象值的比较.对象身份的比较.布尔类型.其中对象值的比较主要是大于.小于.不等于等的数学比较符:对象 ...