Submission #603132

#TimeUsernameProblemLanguageResultExecution timeMemory
603132wiwihoShortcut (IOI16_shortcut)C++14
93 / 100
2077 ms48444 KiB
#include "shortcut.h" #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 1LL << 60; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } int n; vector<ll> p, d, s; ll c; vector<ll> discr; vector<ll> tmp; vector<ll> pos; int lowbit(int x){ return x & -x; } template<typename Comp> struct BIT{ vector<ll> bit; void init(ll v){ bit.resize(n + 1, v); } void reset(ll v){ fill(iter(bit), v); } void modify(int x, ll v){ x = n - x; for(; x < bit.size(); x += lowbit(x)){ bit[x] = min(bit[x], v, Comp()); } } ll query(int x, ll o){ x = n - x; ll ans = o; for(; x > 0; x -= lowbit(x)){ ans = min(ans, bit[x], Comp()); } return ans; } }; BIT<less<>> bitmn; BIT<greater<>> bitmx; struct event{ ll x, y1, y2, ty; bool operator<(event b){ return x < b.x; } }; bool check(ll t){ //cerr << "check " << t << "\n"; //cerr << "tmp "; //printv(tmp, cerr); bitmn.reset(MAX); bitmx.reset(-MAX); vector<event> ev; for(int a = n - 1; a >= 0; a--){ ll X = t - d[a] - c; //cerr << "OAO " << a << "\n";; int id = upper_bound(iter(discr), t - d[a] + p[a]) - discr.begin(); //cerr << "test " << a << " " << id << " " << t - d[a] + p[a] << "\n"; if(id < n){ ll mny = -X + bitmx.query(id, -MAX); ll mxy = X + bitmn.query(id, MAX); if(mny > mxy) return false; mny *= 2; mxy *= 2; ll midx = p[a] * 2; ll midy = (mny + mxy) / 2; ll r = mxy - midy; ll mnx = midx - r; ll mxx = midx + r; //cerr << "rect " << midx << " " << midy << " " << r << "\n"; ll x1 = mnx - midy; ll x2 = mxx - midy; ll y1 = mnx + midy; ll y2 = mxx + midy; ev.eb(event({x1, y1, y2, 0})); ev.eb(event({x2 + 1, y1, y2, 1})); } bitmn.modify(pos[a], -d[a] + p[a]); bitmx.modify(pos[a], d[a] + p[a]); } //cerr << "ok\n"; ll y1 = -MAX, y2 = MAX; ll x1 = -MAX, x2 = MAX; lsort(ev); int sz = ev.size(); int cnt = 0; //cerr << "ok2 " << sz << "\n"; for(int i = 0; i < sz; ){ ll x = ev[i].x; int tc = 0; bool ed = false; for(; i < sz && ev[i].x == x; i++){ //cerr << "do " << i << "\n"; if(ev[i].ty == 1){ x2 = x - 1; ed = true; break; } y1 = max(y1, ev[i].y1); y2 = min(y2, ev[i].y2); x1 = x; tc++; } if(y1 > y2 || ed) break; cnt += tc; } //cerr << "range " << x1 << " " << x2 << " " << y1 << " " << y2 << "\n"; if(y1 > y2 || cnt != sz / 2) return false; for(int i = 0; i < n; i++){ ll x = p[i] * 2; ll mny = max(y1 - x, x - x2); ll mxy = min(y2 - x, x - x1); //cerr << "owo " << i << " " << x << " " << mny << " " << mxy << "\n"; auto it = lower_bound(iter(p), iceil(mny, 2)); if(it != p.end() && *it * 2 <= mxy) return true; } return false; } ll find_shortcut(int _n, vector<int> len, vector<int> _d, int _c){ n = _n; c = _c; p.resize(n); s.resize(n); d.resize(n); for(int i = 0; i < n; i++) d[i] = _d[i]; for(int i = 0; i < n - 1; i++){ p[i + 1] = p[i] + len[i]; } for(int i = 0; i < n; i++){ s[i] = p[i] + d[i]; } bitmn.init(MAX); bitmx.init(-MAX); discr = s; tmp.resize(n); pos.resize(n); iota(iter(tmp), 0); sort(iter(tmp), [&](int x, int y){ return s[x] < s[y]; }); for(int i = 0; i < n; i++){ pos[tmp[i]] = i; } lsort(discr); ll l = 1, r = (ll)(1e9 + 5) * n + (ll)2e9 + 5; while(l < r){ ll m = (l + r) / 2; if(check(m)) r = m; else l = m + 1; } //check(l); return l; }

Compilation message (stderr)

shortcut.cpp: In instantiation of 'void BIT<Comp>::modify(int, ll) [with Comp = std::less<void>; ll = long long int]':
shortcut.cpp:148:42:   required from here
shortcut.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(; x < bit.size(); x += lowbit(x)){
      |               ~~^~~~~~~~~~~~
shortcut.cpp: In instantiation of 'void BIT<Comp>::modify(int, ll) [with Comp = std::greater<void>; ll = long long int]':
shortcut.cpp:149:41:   required from here
shortcut.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...