Skip to content

Instantly share code, notes, and snippets.

@algon-320
Last active July 30, 2016 11:05
Show Gist options
  • Save algon-320/bb74d56e561f1144009bf6f2ccd4baed to your computer and use it in GitHub Desktop.
Save algon-320/bb74d56e561f1144009bf6f2ccd4baed to your computer and use it in GitHub Desktop.
Educational Codeforces Round #15
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
int main(int argc, char const *argv[]) {
int n;
cin>>n;
vector<int> a(n),b(n);
REP(i,n) {
cin>>a[i];
}
int ans=0;
int top=0;
FOR(i,1,n) {
if(a[i]<=a[i-1]) {
ans=max(ans,i-top);
top=i;
}
}
ans=max(ans,n-top);
cout<<ans<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
int main(int argc, char const *argv[]) {
int n;
cin>>n;
vector<ll> a(n);
map<ll,ll> m;
REP(i,n) cin>>a[i], m[a[i]]++;
ll ans = 0;
REP(i,n) {
REP(k,31) {
ans += (m[(1<<(k+1))-a[i]]);
if(a[i]*2==(1<<(k+1))) ans--;
}
}
cout<<ans/2<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment