제출 #116853

#제출 시각아이디문제언어결과실행 시간메모리
116853puppies_and_rainbowsSan (COCI17_san)C++14
72 / 120
740 ms39244 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int h[100], g[100]; vector<int> adj[100]; vector<int> th[100]; pair<int, int> a[100]; int n, k; vector<int> cac; int nodecnt=0; int bit[1000005]; multiset<int> s; int ans=0; int putin[100005]; unordered_map<int, int> pos; void update(int pos) { while(pos<=nodecnt) { bit[pos]++; pos+=pos&-pos; } } int get(int pos) { int ans=0; while(pos>=1) { ans+=bit[pos]; pos-=pos&-pos; } return ans; } void dfs(int node) { for(auto i:adj[node]) { for(auto j:th[node]) { th[i].push_back(j+g[i]); } } } signed main() { cin>>n>>k; for(int i=1; i<=n; i++) { cin>>h[i]>>g[i]; a[i].first=h[i]; a[i].second=i; } for(int i=1; i<=n/2; i++) { for(int j=i+1; j<=n/2; j++) { if(h[j]>=h[i]) { adj[i].push_back(j); } } } for(int i=n; i>=n/2+1; i--) { for(int j=i-1; j>=n/2+1; j--) { if(h[j]<=h[i]) { adj[i].push_back(j); } } } for(int i=1; i<=n/2; i++) { th[i].push_back(g[i]); dfs(i); } for(int i=n; i>=n/2+1; i--) { th[i].push_back(g[i]); dfs(i); } sort(a+1, a+n/2+1); sort(a+n/2+1, a+n+1); int itj=n; cac.push_back(-1); cac.push_back(0); for(int i=n; i>=n/2+1; i--) { for(auto j:th[i]) { cac.push_back(j); } } cac.push_back(1000000000000); sort(cac.begin(), cac.end()); for(int i=1; i<cac.size(); i++) { if(cac[i]!=cac[i-1]) { nodecnt++; pos[cac[i]]=nodecnt; } } // update(1); // for(int i=1; i<=n/2; i++) // { // for(auto j:th[i]) // { // cout<<j<<" "; // } // cout<<endl; // } int takens=0; takens++; update(1); for(int i=n/2; i>=1; i--) { while(a[itj].first>=a[i].first&&itj>=n/2+1) { // cout<<a[i].second<<" "<<a[itj].second<<endl; for(auto j:th[a[itj].second]) { update(pos[j]); takens++; } itj--; } for(auto j:th[a[i].second]) { // if(j>=k) ans++; int concac=*lower_bound(cac.begin(), cac.end(),max(k-j,0ll)); // cout<<concac<<" "<<j<<" "<<max(pos[concac]-1, 0ll)<<" "<<takens<<endl; ans+=takens-get(pos[concac]-1); } } int concac=*lower_bound(cac.begin(), cac.end(), k); ans+=takens-get(pos[concac]-1); cout<<ans; }

컴파일 시 표준 에러 (stderr) 메시지

san.cpp: In function 'int main()':
san.cpp:102:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<cac.size(); i++)
               ~^~~~~~~~~~~
#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...