码迷,mamicode.com
首页 > 其他好文 > 详细

利用MAP存数据,防止超时,一开始用了两个for 循环CodeForces - 702B

时间:2018-06-07 20:11:05      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:space   class   bit   using   pretty   map   cpp   lang   main   

#include<bits/stdc++.h>

using namespace std;

map <int,int> M;

long long ans;

int main()
{
	int n,a;
	cin>>n;
	while(n--)
	{
		cin>>a;
		for(int i=0;i<=31;i++)
		    ans+=M[(1LL<<i)-a];
		M[a]++;
	}
	cout<<ans;
}

利用MAP存数据,防止超时,一开始用了两个for 循环CodeForces - 702B

标签:space   class   bit   using   pretty   map   cpp   lang   main   

原文地址:https://www.cnblogs.com/wangzhelin/p/9152476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!