日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Codeforces Gym 100187M M. Heaviside Function two pointer

發布時間:2024/4/15 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Gym 100187M M. Heaviside Function two pointer 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

M. Heaviside Function

Time Limit: 20 Sec

Memory Limit: 256 MB

題目連接

http://codeforces.com/gym/100187/problem/M

Description

Heaviside function is defined as the piecewise constant function whose value is zero for negative argument and one for non-negative argument:


You are given the function f(x)?=?θ(s1x?-?a1)?+?θ(s2x?-?a2)?+?...?+?θ(snx?-?an), where si?=??±?1. Calculate its values for argument values x1, x2, ..., xm.

Input

The first line contains a single integer n (1?≤?n?≤?200000) — the number of the summands in the function.

Each of the next n lines contains two integers separated by space — si and ai (si?=??±?1, ?-?109?≤?ai?≤?109) — parameters of the i-th summand.

The next line contains a single integer m (1?≤?m?≤?200000) — the number of the argument values you should calculate the value of the function for.

The last line contains m integers x1, ..., xm (?-?109?≤?xi?≤?109) separated by spaces — the argument values themselves.

Output

Output m lines. i-th line should contain the value of f(xi).

Sample Input

6
1 3
-1 2
1 9
-1 2
1 7
-1 2
8
0 12 2 8 4 -3 7 9

Sample Output

0
3
0
2
1
3
2
3

HINT

?

題意

if(sx-a>=0)ans++;問你每個數通過這個公式,最后的ans是多少

題解:

當s=1時,很顯然這個直線是單調向上的,我們可以利用two pointer來優化就好了

復雜度O(n+m)

代碼

#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200101 #define mod 1000000009 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //**************************************************************************************struct node {int x,y; };bool cmp1(node a,node b) {return a.x<b.x; } bool cmp2(node a,node b) {return a.y<b.y; } node a[maxn]; vector<int> a1; vector<int> a2; node b[maxn]; int ans[maxn];int main() {int flag1=0,flag2=0;int n=read();for(int i=0;i<n;i++){a[i].x=read(),a[i].y=read();if(a[i].x==1)flag1++,a1.push_back(a[i].y);elseflag2++,a2.push_back(a[i].y);}int m=read();for(int i=0;i<m;i++)b[i].x=read(),b[i].y=i;sort(b,b+m,cmp1);sort(a1.begin(),a1.end());sort(a2.begin(),a2.end());for(int i=m-1;i>=0;i--){if(flag1==0)break;while(b[i].x<a1[flag1-1]&&flag1>0)flag1--;if(flag1==0)break;ans[b[i].y]+=flag1;}for(int i=0;i<m;i++){if(flag2==0)break;while(b[i].x>-a2[flag2-1]&&flag2>0)flag2--;if(flag2==0)break;ans[b[i].y]+=flag2;}for(int i=0;i<m;i++)printf("%d\n",ans[i]); }

?

總結

以上是生活随笔為你收集整理的Codeforces Gym 100187M M. Heaviside Function two pointer的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲一区有码 | 国产一区 在线播放 | www.伊人| 铠甲勇士猎铠 | 国产午夜精品久久久久久久久久 | 国产成人无码av | 日韩欧美一区二区视频 | 91大神精品| 免费操人视频 | 18禁网站免费无遮挡无码中文 | 制服下的诱惑暮生 | 阿的白色内裤hd中文 | 日本在线播放 | 秋霞成人午夜鲁丝一区二区三区 | 射进来av影视网 | 艳妇臀荡乳欲伦交换在线看 | 91爱看| 一二三四精品 | 丰满熟女人妻一区二区三区 | 欧美激情在线观看一区 | 好看的黄色录像 | 午夜小视频在线播放 | 欧美人妖老妇 | 精品98| 久久国产精品一区二区三区 | 五月天综合视频 | 生活片毛片 | 欧美丰满美乳xxⅹ高潮www | 免费久久久久久 | 一区二区三区在线视频观看 | 乳罩脱了喂男人吃奶视频 | 小泽玛利亚一区二区三区 | 国产欧美日韩高清 | 日韩av无码一区二区三区 | 男女猛烈无遮挡免费视频 | 黄色资源网 | 国产精品国产精品 | 一边吃奶一边摸做爽视频 | 亚洲综合自拍偷拍 | 日本午夜激情视频 | 中国性猛交 | 樱花动漫无圣光 | 久久久av电影 | 午夜爽爽爽视频 | 天堂资源在线播放 | 男女草逼 | 女子spa高潮呻吟抽搐 | 免费网站在线观看人数在哪动漫 | 内射后入在线观看一区 | 91成人国产综合久久精品 | 大陆极品少妇内射aaaaa | 精品视频无码一区二区三区 | 国产精品一区二区免费在线观看 | 日本国产一区二区三区 | 亚洲视频自拍 | 男男做爰猛烈叫床爽爽小说 | 日本人视频69式jzzij | 91国产一区| 黄色www视频 | 黄色片www | 自拍偷拍2019| 久久免费视频网站 | 一区二区三区国产在线观看 | 国产av剧情一区 | 成人免费网站黄 | 爱爱精品视频 | 久久精品国产网红主播 | 日本视频www | 国产美女91| 99精品视频一区二区三区 | 野外做受又硬又粗又大视频√ | 五色天婷婷 | 日韩欧美网| 高清国产午夜精品久久久久久 | 久久久资源 | 亚洲国产精品毛片av不卡在线 | 午夜美女福利视频 | 美女干b视频 | 蜜桃av久久久亚洲精品 | 中日韩在线播放 | www.超碰在线观看 | 日本a视频| 亚洲电影影音先锋 | 日本公妇乱淫免费视频一区三区 | 日本中文字幕不卡 | 国产午夜网站 | 伊人逼逼 | 日本精品一区二区视频 | 亚洲免费av网址 | 日本天堂影院 | 玩偶姐姐在线观看免费 | 国产av一区二区三区传媒 | 狂野欧美性猛交xxxxhd | 精品一区李梓熙捆绑 | 欧美精品91 | 99久久精品一区 | 一本到久久 | 麻豆国产网站 | xiuxiuavnet|