ii> P) { dd> v) { if (v.size (v.size() () == 1) return MN; int M = v.size v.size()/ ()/2; 2; vector
12.
GEOMETRY (4)
sort(P.begin(),P.end()); P.erase(unique(P.begin(),P.end()),P.end()); if (P.size (P.size() () == 1) return P; int n = P.size P.size(); (); vector
40
} pair
bot.insert(bot.end(),all(up)); return bot; }
auto z = strip(V,d strip(V,di); i); return min(min(a,b),z);
int main() main() { int n; while (cin >> n) { if (n == 0) break; break; vector vector
12.2.2 12.2.2
} int main() main() { cout << fixed << setprecis setprecision(2 ion(2); ); while (cin >> n) { if (n == 0) break; break; vector
Close Closest st Pair Pair (6) (6) 12.2.3 12.2.3
/** * Sourc Source: e: Geeks GeeksForG ForGeeks eeks * Descr Descriptio iption: n: Nlog Nlog^2N, ^2N, can be impro improved ved * Use: https://open.kattis https://open.kattis.com/problems/close .com/problems/closestpair2 stpair2 */ pair
LineCo LineCont ntain ainer er (6)
/** * Sou Source rce: : KAC KACTL TL * Veri Verificat fication: ion: CSA Squar Squared ed Ends */ bool Q; struct Line Line { mutable ll k, m, p; // slope slope, , y-in y-interce tercept, pt, last las t opt optima imal l x bool opera operator tor<( <(const const Line& Line& o) const { return Q ? p < o . p : k < o . k ; } }; struct LineContain LineContainer er : multiset
13.
ADDITIONAL (4)
ll div(ll a, ll b) { // floo floored red divis division ion if (b < 0) a *= -1, b *= -1; if (a >= 0) return a/b; return -((-a+b-1)/b); }
FOR(i,1,n+1) if (i*(i (i*(i-1) -1)/2 /2 <= mx) ans = i; cout cout << ans ans << "\n"; "\n"; }
// upd update ates s x-> x->p, p, det determ ermine ines s if y is unn unneed eeded ed bool isect(ite isect(iterator rator x, iterator iterator y) { if (y == end()) { x->p = inf; return 0; } if (x-> (x->k k == y->k) y->k) x->p x->p = x->m x->m > y->m y->m ? inf : -inf; -inf; else x->p x->p = div( div(yy->m >m - x->m x->m, , x->k x->k y->k); return x->p x->p >= y->p; y->p; }
13
void add(ll k, ll m) { auto z = insert({k, m, 0}), y = z++, x = y; while (isect (isect(y, (y, z)) z = erase( erase(z); z); if (x != begin( begin() ) && isect( isect(--x --x, , y)) isect(x, isect(x, y = erase(y)) erase(y)); ; while ((y = x) != begi begin( n() ) && (--x (--x))->p >p >= y->p) isect(x, erase(y)); erase(y)); }
int block block = 300; 300; // set ~sq ~sqrt( rt(N) N)
ll quer query( y(ll ll x) { // giv gives es max value assert(!empty()); Q = 1 ; auto l = *lb( *lb({0 {0,0 ,0,x ,x}) }); ; Q = 0; return l.k * x + l.m; } };
12.3 12.3
41
Max Max Coll Collin inea earr
13.1
Add ddit itio ion nal (4) Mo
/** * Sour Source: ce: Codef Codeforces orces * Desc Descripti ription: on: Answe Answers rs queri queries es offl offline ine in (N+Q) (N+Q)sqrt sqrt(N) (N) * Al Also so se see e Mo Mo’s ’s on tr tree ees s */
bool cmp(vi a, vi b) { if (a[0]/block (a[0]/block != b[0]/block b[0]/block) ) return a[0] a[0] < b[0]; b[0]; return a[1] a[1] < b[1]; b[1]; }
13.2
Misc
13.2.1 13.2.1
Discret Discrete e Logari Logarithm thm
/** * Descr Descriptio iption: n: find k such that primi primitive^ tive^k=x k=x * mee meet t in the mid middle dle, , O(s O(sqrt qrt(MO (MOD)) D)) * Sou Source rce: : Own * Ver Verifi ificat cation ion: : PA 200 2006 6 - Pro Profes fessor sor Lau Laugh’ gh’s s Num Number bers s */ const int BLOCK BLOCK = 32000; 32000;
/** * Sou Source rce: : own * Usage: https://open.katt https://open.kattis.com/problems/max is.com/problems/maxcolinear colinear */ int n, mx, mx, ans; ans; map
int primitive primitive = 5, invy[BLOC invy[BLOCK]; K]; unordered_map
pair
ll query( query(int x) { F0R(i,BLOCK) if (u.count(x*invy[i]%MOD)) return i*BLOCK+u[x*invy[i]%MOD]; return -1; } int main() main() { ll cur = 1; F0R(i,BLOC F0R(i,BLOCK) K) { u[cu u[cur] r] = i; cur = primitive* primitive*cur%M cur%MOD; OD; } ll t = 1; F0R(i,BLOC F0R(i,BLOCK) K) {
13.
ADDITIONAL (4)
invy[i] invy[i] = inv(t); inv(t); t = t*cur% t*cur%MOD MOD; ; } ll x; cin >> x; cout cout << query( query(x) x) << "\n"; "\n"; }
13.3 13.3
Pragma Pragma Optimi Optimizat zation ion (6)
/** * Sou Source rce: : Mis Misc c sol soluti utions ons to CF Nag Nagini ini * Descr Descriptio iption: n: 10^{1 10^{10} 0} opera operations tions are ok! * Pas Passes ses the occ occasi asiona onal l dis disgus gustin ting g CF tas task k * Als Also o see "We "Welco lcome me hom home, e, Cht Chthol holly" ly" */ #pragma GCC optimi optimize ze ("O3" "O3") ) #pragma GCC target target ("sse4" "sse4") ) int q, mx[100001 mx[100001], ], mn[100001] mn[100001]; ; int main() main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> q; F0R(i, F0R(i,100 100001 001) ) mx[i] mx[i] = -MOD, -MOD, mn[i] mn[i] = MOD; MOD; F0R(i,q) F0R(i,q) { int t,l,r,k; cin >> t >> l >> r; r -= l; auto a = mx+l, b = mn+l; if (t == 1) { cin >> k; if (k > 0) F0R(j, F0R(j,r) r) b[j] b[j] = min(b[ min(b[j], j],k); k); else F0R(j,r) F0R(j,r) a[j] = max(a[j], max(a[j],k); k); } else { ll ans = 0; F0R(j,r) if (a[j] (a[j] != -MOD -MOD && b[j] b[j] != MOD) MOD) ans += b[j]-a[j] b[j]-a[j]; ; cout cout << ans ans << "\n"; "\n"; } } }
42