P1102 A-B 数对 - 洛谷这道题明显不能暴力这一题将A-BC转换成A-CB将a数组每个元素的次数存在map容器中b[i]a[i]-cb[i]在map容器中出现将次数加起来就是数对的个数#includebits/stdc.h using namespace std; typedef long long LL; const int N2e55; LL a[N],b[N]; mapLL,LL m; int main(){ int n; LL c; LL ans0; cinnc; for(int i0;in;i){ cina[i]; m[a[i]]; b[i]a[i]-c; } for(int i0;in;i) ansm[b[i]]; coutans; return 0; }P5250 【深基17.例5】木材仓库 - 洛谷先“假装”存一下该不存在的木头然后指针定位该木头的位置it2指向y本身it指向比y大的第一个元素--it2指向比y小的第一个元素#includebits/stdc.h using namespace std; typedef long long LL; int main(){ mapint,intmp; LL x,y; int m; cinm; while(m--){ cinxy; if(x1){ if(mp.count(y)) coutAlready Existendl; else mp[y]1; } else{ if(mp.empty()) coutEmptyendl; else if(mp.count(y)){ mp.erase(y); coutyendl; } else{ mp[y]1; auto itmp.find(y); auto it2it; it; if(it2mp.begin()){ coutit-firstendl; mp.erase(it); } else if(itmp.end()){ cout(--it2)-firstendl; mp.erase(it2); } else if(y-(--it2)-firstit-first-y){ coutit-firstendl; mp.erase(it); } else{ coutit2-firstendl; mp.erase(it2); } mp.erase(y); } } } return 0; }