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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ

發(fā)布時(shí)間:2023/11/30 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題意:

給定一個(gè)序列,問在這個(gè)序列里有多少區(qū)間第k的的數(shù)>=m

思路:

在比賽的時(shí)候是多想了,開始像區(qū)間第k大的問題,賽后想想實(shí)在是偏了。

正確的解法是枚舉起點(diǎn)然后用尺取法維護(hù)一段區(qū)間,直到找到k個(gè)數(shù)>=m的最短終點(diǎn)r,ans便是后邊這一小段即n-r+1。

code:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=0x3fffffff; const int inf=-INF; const int N=200005; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define cpy(x,a) memcpy(x,a,sizeof(a)) #define ft(i,s,n) for (int i=s;i<=n;i++) #define frt(i,s,n) for (int i=s;i>=n;i--) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin) #define OUT freopen("out.txt","w",stdout)int read() {char ch;while (ch = getchar(), !isdigit(ch));int res = ch - '0';while (ch = getchar(), isdigit(ch))res = res * 10 + ch - '0';return res; } //++++++++++++密++++++++++++++封++++++++++++++++++++線 int a[N]; int main() {int T=read();while (T--){int n=read(),m=read(),k=read();for (int i=1;i<=n;i++) a[i]=read();int num=0,r=0;ll ans=0; //num表示大于m的個(gè)數(shù),r為最短終點(diǎn)for (int i=1;i<=n;i++){while (num<k&&r<n){r++;num+=(a[r]>=m);}if (num<k) break;ans+=n-r+1;num-=(a[i]>=m);}printf("%I64d\n",ans);} }

總結(jié)

以上是生活随笔為你收集整理的BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。