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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

2018ICPC南京赛区网络选拔B The writing on the wall (单调栈)

發(fā)布時間:2024/10/12 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2018ICPC南京赛区网络选拔B The writing on the wall (单调栈) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#2018ICPC南京賽區(qū)網(wǎng)絡(luò)選拔B The writing on the wall (單調(diào)棧)
###題目鏈接:
https://nanti.jisuanke.com/t/30991
###代碼:

#include<bits/stdc++.h> using namespace std; const int maxn=1e5+5; #define push_back pb; vector<int>Q[maxn]; pair<int,int>P[maxn]; int h[maxn]; int main() {int n,m,T,i,j,k,s;long long ans;int x,y;scanf("%d",&T);for(s=1;s<=T;s++){ans=0;scanf("%d%d%d",&m,&n,&k);for(i=1;i<=k;i++){scanf("%d%d",&P[i].second,&P[i].first);}sort(P+1,P+1+k);int temp=1;memset(h,0,sizeof(h));for(i=1;i<=n;i++){for(j=1;j<=m;j++){if(temp<=k&&P[temp].first==i&&P[temp].second==j){// cout<<"-------------"<<endl;temp++;h[j]=0;}else h[j]++;}int top=0;int sta[maxn];h[0]=0;sta[++top]=0;long long subans=0;for(j=1;j<=m;j++){while(top>0&&h[j]<=h[sta[top]]){subans-=1ll*h[sta[top]]*(sta[top]-sta[top-1]);top--;}sta[++top]=j;subans+=1ll*h[sta[top]]*(sta[top]-sta[top-1]);ans+=subans;}}printf("Case #%d: %lld\n",s,ans);} }

轉(zhuǎn)載于:https://www.cnblogs.com/na7-TRZNDP-Z/p/9782451.html

總結(jié)

以上是生活随笔為你收集整理的2018ICPC南京赛区网络选拔B The writing on the wall (单调栈)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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