제출 #1028196

#제출 시각아이디문제언어결과실행 시간메모리
1028196AbitoJobs (BOI24_jobs)C++17
29 / 100
488 ms204444 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define ll long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=3e5+5; int a[N],n,dp[N],c[N],p[N],lg[N]; vector<vector<int>> ps,g,s[20]; int query(int i,int l,int r){ if (l>r) swap(l,r); int j=lg[r-l+1]; return min(s[j][i][l],s[j][i][r-(1<<j)+1]); } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); for (int i=2;i<N;i++) lg[i]=lg[i/2]+1; cin>>n>>a[0]; int ans=a[0]; for (int i=1;i<=n;i++){ cin>>a[i]>>p[i]; c[p[i]]=i; } priority_queue<vector<int>> pq; for (int i=1;i<=n;i++){ if (p[i]) continue; vector<int> b; b.pb(a[i]); int x=i; while (c[x]){ x=c[x]; b.pb(a[x]); } ps.pb({});g.pb({}); g.back().resize(b.size(),-1); ps.back().pb(b[0]); for (int i=1;i<b.size();i++){ ps.back().pb(ps.back().back()+b[i]); } stack<int> st; for (int i=b.size()-1;i>=0;i--){ while (!st.empty() && ps.back()[st.top()]<=ps.back()[i]) st.pop(); if (!st.empty()) g.back()[i]=st.top(); st.push(i); } for (int j=0;j<20;j++) s[j].pb(ps.back()); for (int j=1;j<20;j++){ for (int k=0;k+(1<<j)<=b.size();k++) s[j].back()[k]=min(s[j-1].back()[k],s[j-1].back()[k+(1<<(j-1))]); } /*for (int j=0;j<20;j++){ for (int k=0;k<b.size();k++) cout<<s[j].back()[k]<<' ';cout<<endl; }*/ for (int i=0;i<b.size();i++){ if (ps.back()[i]<=0) continue; //cout<<query(ps.size()-1,0,i)<<endl; pq.push({query(ps.size()-1,0,i),ps.size()-1,i,-1}); break; } //for (auto u:ps.back()) cout<<u<<' ';cout<<endl; //for (auto u:g.back()) cout<<u<<' ';cout<<endl; } while (!pq.empty()){ int i=pq.top()[1],j=pq.top()[2],last=pq.top()[3],mn=pq.top()[0]; pq.pop(); //cout<<ans<<' '<<i<<' '<<j<<' '<<mn<<' '<<last<<endl; if (ans+mn<0) break; ans+=ps[i][j]; if (last>=0) ans-=ps[i][last]; if (g[i][j]==-1) continue; int k=g[i][j]; pq.push({query(i,last+1,k)-ps[i][j],i,k,j}); } cout<<ans-a[0]<<endl; return 0; }

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

Main.cpp: In function 'int32_t main()':
Main.cpp:46:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i=1;i<b.size();i++){
      |                      ~^~~~~~~~~
Main.cpp:57:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int k=0;k+(1<<j)<=b.size();k++) s[j].back()[k]=min(s[j-1].back()[k],s[j-1].back()[k+(1<<(j-1))]);
      |                          ~~~~~~~~^~~~~~~~~~
Main.cpp:62:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i=0;i<b.size();i++){
      |                      ~^~~~~~~~~
Main.cpp:65:54: warning: narrowing conversion of '(ps.std::vector<std::vector<long long int> >::size() - 1)' from 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   65 |             pq.push({query(ps.size()-1,0,i),ps.size()-1,i,-1});
      |                                             ~~~~~~~~~^~
Main.cpp:65:54: warning: narrowing conversion of '(ps.std::vector<std::vector<long long int> >::size() - 1)' from 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
#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...