제출 #65767

#제출 시각아이디문제언어결과실행 시간메모리
65767reality공장들 (JOI14_factories)C++17
18 / 100
8058 ms237564 KiB
#include "factories.h" #include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;} template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;} template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} int n; const int N = 2e6 + 5; vector < pii > g[N]; int * SZ; void dfs_sz(int v = 0) { SZ[v] = 1; for (auto & u : g[v]) { if (SZ[u.fi] != -1) continue; dfs_sz(u.fi); smax(SZ[v],SZ[u.fi] + 1); if (SZ[u.fi] >= SZ[g[v][0].fi]) swap(u, g[v][0]); } } int * in; int * out; int * rin; int * nxt; int * pr; int Time = 0; ll * D; void dfs_hld(int v = 0) { in[v] = ++Time; rin[in[v]] = v; for (auto u : g[v]) { if (D[u.fi] != -1) continue; nxt[u.fi] = (u == g[v][0] ? nxt[v] : u.fi); D[u.fi] = u.se + D[v]; pr[u.fi] = v; dfs_hld(u.fi); } out[v] = Time; } void Init(int NN, int A[], int B[], int DD[]) { n = NN; D = new ll[n + 5]; pr = new int[n + 5]; SZ = new int[n + 5]; in = new int[n + 5]; out = new int[n + 5]; nxt = new int[n + 5]; rin = new int[n + 5]; for (int i = 0;i < n;++i) { g[A[i]].pb(mp(B[i],DD[i])); g[B[i]].pb(mp(A[i],DD[i])); } for (int i = 0;i < n;++i) SZ[i] = D[i] = -1; D[0] = 0; dfs_sz(); dfs_hld(); pr[0] = -1; } vector < pair < ll , int > > add[N],del[N]; long long Query(int SS, int X[], int T, int Y[]) { vi a,b; for (int i = 0;i < SS;++i) a.pb(X[i]); for (int i = 0;i < T;++i) b.pb(Y[i]); vector < pii > v1,v2; vi i1,i2; for (auto it : a) { int node = it; while (node >= 0) { v1.pb(mp(in[nxt[node]],in[node])); i1.pb(it); node = pr[nxt[node]]; } } for (auto it : b) { int node = it; while (node >= 0) { v2.pb(mp(in[nxt[node]],in[node])); i2.pb(it); node = pr[nxt[node]]; } } set < ll > ss; for (auto it : v1) ss.insert(it.fi),ss.insert(it.se); for (auto it : v2) ss.insert(it.fi),ss.insert(it.se); vector < ll > w(all(ss)); for (auto & it : v1) { it.fi = lower_bound(all(w),it.fi) - w.begin() + 1; it.se = lower_bound(all(w),it.se) - w.begin() + 1; } for (auto & it : v2) { it.fi = lower_bound(all(w),it.fi) - w.begin() + 1; it.se = lower_bound(all(w),it.se) - w.begin() + 1; } ll ans = 1e18; multiset < ll > S[2]; const int sz1 = v1.size(); const int sz2 = v2.size(); for (int i = 0;i < sz1;++i) { auto it = v1[i]; add[it.fi].pb(mp(D[i1[i]],0)); del[it.se].pb(mp(D[i1[i]],0)); } for (int i = 0;i < sz2;++i) { auto it = v2[i]; add[it.fi].pb(mp(D[i2[i]],1)); del[it.se].pb(mp(D[i2[i]],1)); } for (int i = 1;i <= w.size();++i) { for (auto it : add[i]) { S[it.se].insert(it.fi); } if (!S[0].empty() && !S[1].empty()) { smin(ans,*S[0].begin() + *S[1].begin() - 2 * D[rin[w[i - 1]]]); } for (auto it : del[i]) { S[it.se].erase(S[it.se].find(it.fi)); } add[i].clear(); del[i].clear(); } return ans; }

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

factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:143:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1;i <= w.size();++i) {
                 ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...