返回题解分享
讨论 / 题解分享/ 帖子详情

最小公倍数 - 题解

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 9;
map<int,int>mp1;
map<pair<int,int>,int>mp2;
vector<pair<int,int>> a[N];
signed main(){
int n;cin>>n;
for(int i=1;i<=n;i++){
int m;cin>>m;
for(int j=1;j<=m;j++){
int x,y;
cin>>x>>y;
a[i].push_back({x,y});
mp1[x] = max(mp1[x],y);
mp2[{x,y}]++;
}
}
int res = 0,f1 = 1;
for(int i = 1;i <=n;i++){
int f = 0;
for(int j = 0;j < a[i].size();j++){
if(mp2[a[i][j]]==1 && mp1[a[i][j].first] == a[i][j].second){
f = 1;
}
}
if(f == 1) res++;
else{
res += f1;
f1 = 0;
}

}
cout<<res;
return 0;
}
``````
0 回复 0 转发 0 喜欢 8 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!