Submission #166031

#TimeUsernameProblemLanguageResultExecution timeMemory
166031theStaticMindSan (COCI17_san)C++14
120 / 120
61 ms4088 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n,k,ans=0; cin>>n>>k; vector<int>arr(n+1,0),gold(n+1,0); map<int,map<int,int>>data,atad; data[0][0]=1; atad[INF][0]=1; for(int i=1;i<=n;i++)cin>>arr[i]>>gold[i]; for(int i=1;i<=n/2;i++){ map<int,int>temp; for(map<int,map<int,int>>::iterator it=data.begin();it!=data.end()&&it->first<=arr[i];it++){ for(map<int,int>::iterator itr=it->second.begin();itr!=it->second.end();itr++){ if(itr->first+gold[i]>=k){ temp[k]+=itr->second; } else temp[itr->first+gold[i]]+=itr->second; } } for(map<int,int>::iterator itr=temp.begin();itr!=temp.end();itr++)data[arr[i]][itr->first]+=itr->second; } for(int i=n;i>n/2;i--){ map<int,int>temp; for(map<int,map<int,int>>::reverse_iterator it=atad.rbegin();it!=atad.rend()&&it->first>=arr[i];it++){ for(map<int,int>::iterator itr=it->second.begin();itr!=it->second.end();itr++){ if(itr->first+gold[i]>=k){ temp[k]+=itr->second; } else temp[itr->first+gold[i]]+=itr->second; } } for(map<int,int>::iterator itr=temp.begin();itr!=temp.end();itr++)atad[arr[i]][itr->first]+=itr->second; } map<int,map<int,int>>::iterator itrA=data.begin(),itrB=atad.begin(); map<int,int>meet; for(;itrB!=atad.end();itrB++){ while(itrA!=data.end()&&itrA->first<=itrB->first){ for(map<int,int>::iterator itr=itrA->second.begin();itr!=itrA->second.end();itr++){ meet[itr->first]+=itr->second; } itrA++; } map<int,int>::reverse_iterator curr=meet.rbegin(); map<int,int> prefix; int cnt=0; for(;curr!=meet.rend();curr++){ prefix[curr->first]=curr->second+cnt; cnt+=curr->second; } for(map<int,int>::iterator itr=itrB->second.begin();itr!=itrB->second.end();itr++){ map<int,int>::iterator get=prefix.lower_bound(k-itr->first); if(get!=prefix.end())ans+=get->second*itr->second; } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...