Submission #876027

#TimeUsernameProblemLanguageResultExecution timeMemory
876027RegulusRoad Construction (JOI21_road_construction)C++17
0 / 100
247 ms10796 KiB
#include <bits/stdc++.h> // pA #define IO ios::sync_with_stdio(false);cin.tie(0); #define debug(x) cerr << #x << " = " << (x) << ' ' #define endl cerr << '\n' #define all(v) (v).begin(), (v).end() #define lowbit(x) (x)&-(x) #define pb emplace_back #define F first #define S second using namespace std; using ll = long long; using pll = pair<ll, ll>; const int N = 2e5+5; const ll INF = 1e18; ll Seg[N<<2]; pll p[N]; vector<ll> com; inline void build(ll L, ll R, ll v) { Seg[v] = INF; if (L != R) build(L, (L+R)>>1, v<<1), build(((L+R)>>1)+1, R, v<<1|1); } inline ll query(ll L, ll R, ll ql, ll qr, ll v) { if (ql > qr) return INF; if (ql <= L && R <= qr) return Seg[v]; int mid((L+R)>>1); if (qr <= mid) return query(L, mid, ql, qr, v<<1); if (ql > mid) return query(mid+1, R, ql, qr, v<<1|1); return min(query(L, mid, ql, mid, v<<1), query(mid+1, R, mid+1, qr, v<<1|1)); } inline void update(ll L, ll R, ll v, ll pos, ll val) { if (L == R) { Seg[v] = val; return; } int mid((L+R)>>1); if (pos <= mid) update(L, mid, v<<1, pos, val); else update(mid+1, R, v<<1|1, pos, val); Seg[v] = min(Seg[v<<1], Seg[v<<1|1]); } int main(void) { IO ll n, i, Q, j, mn=INF, tmp, ttmp; cin >> n >> Q; if (Q != 1) assert(0); for (i=1; i <= n; ++i) cin >> p[i].F >> p[i].S, com.pb(p[i].S); sort(p+1, p+n+1); sort(all(com)); com.resize(unique(all(com))-com.begin()); //for (i=1; i <= n; ++i) debug(p[i].F), debug(p[i].S), endl; build(1, com.size(), 1); for (i=1; i <= n; ++i) { tmp = lower_bound(all(com), p[i].S) - com.begin() + 1; ttmp = query(1, com.size(), 1, tmp, 1); mn = min(mn, p[i].F+p[i].S + ttmp); update(1, com.size(), 1, tmp, -p[i].F-p[i].S); } build(1, com.size(), 1); for (i=1; i <= n; ++i) { tmp = lower_bound(all(com), p[i].S) - com.begin() + 1; ttmp = query(1, com.size(), tmp+1, com.size(), 1); mn = min(mn, p[i].F-p[i].S + ttmp); update(1, com.size(), 1, tmp, -p[i].F+p[i].S); } cout << mn << '\n'; return 0; }

Compilation message (stderr)

road_construction.cpp: In function 'int main()':
road_construction.cpp:47:17: warning: unused variable 'j' [-Wunused-variable]
   47 |     ll n, i, Q, j, mn=INF, tmp, ttmp;
      |                 ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...