This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long n,k,a[44],b[44],nm,tree[1000006],ans;
vector<pair<long long,long long> >on,to;
vector<long long>tk;
map<long long,long long>mp;
void up(int nod,int l,int r,int x)
{
if(x<l||r<x)return;
if(l==r)
{
tree[nod]++;
return;
}
int mid=(l+r)/2;
up(nod*2,l,mid,x);
up(nod*2+1,mid+1,r,x);
tree[nod]=tree[nod*2]+tree[nod*2+1];
}
long long qr(int nod,int l,int r,int x,int y)
{
if(x<=l&&r<=y)return tree[nod];
if(y<l||r<x)return 0;
int mid=(l+r)/2;
return qr(nod*2,l,mid,x,y)+qr(nod*2+1,mid+1,r,x,y);
}
void bt(int x,int y,int mx,long long sum)
{
if(y==mx+1)
{
if(sum>=k)ans++;
if(sum>0)
{
if(mx==n/2)on.push_back({a[x],sum});
else
{
to.push_back({a[x],sum});
tk.push_back(sum);
}
}
return;
}
if(a[x]<=a[y])bt(y,y+1,mx,sum+b[y]);
bt(x,y+1,mx,sum);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("gpsduel.in","r",stdin);
//freopen("gpsduel.out","w",stdout);
cin>>n>>k;
for(int i=1; i<=n; i++)cin>>a[i]>>b[i];
bt(0,1,n/2,0);
bt(0,(n/2)+1,n,0);
sort(on.begin(),on.end());
sort(to.begin(),to.end());
sort(tk.begin(),tk.end());
for(int i=0; i<tk.size(); i++)
{
if(mp[tk[i]]==0)mp[tk[i]]=++nm;
}
int l=to.size()-1;
for(int i=on.size()-1; i>=0; i--)
{
long long x=on[i].first,y=on[i].second;
for(l; l>=0; l--)
{
if(to[l].first<x)break;
long long sm=to[l].second;
up(1,0,tk.size()+45,mp[sm]);
}
if(lower_bound(tk.begin(),tk.end(),k-y)!=tk.end())
{
long long kk=*lower_bound(tk.begin(),tk.end(),k-y);
ans+=qr(1,0,tk.size()+45,mp[kk],tk.size()+45);
}
}
cout<<ans;
}
Compilation message (stderr)
san.cpp: In function 'int main()':
san.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<tk.size(); i++)
~^~~~~~~~~~
san.cpp:69:14: warning: statement has no effect [-Wunused-value]
for(l; l>=0; l--)
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |