测试点3很耗时,printf和scanf就快一点了
#include <iostream>
#include <map>
using namespace std;
int main(){
int n,k,temp;
scanf("%d", &n);
map<int,int> m;
for(int i=0;i<n;i++){scanf("%d", &temp);m[temp]++;}
scanf("%d", &k);
for(int i=0;i<k;i++){
scanf("%d", &temp);
if(i!=0) printf(" ");
printf("%d", m[temp]);
}
return 0;
}
第一次代码,测试点3的时间太长了,后来把所有的cin和cout换掉就好多了
#include <iostream>
#include <map>
using namespace std;
int main(){
int n,k,temp;
cin>>n;
map<int,int> m;
for(int i=0;i<n;i++){cin>>temp; m[temp]++;}
cin>>k;
for(int i=0;i<k;i++){
cin>>temp;
if(i!=k-1) cout<<m[temp]<<" ";
else cout<<m[temp];
}
return 0;
}