제출 #235203

#제출 시각아이디문제언어결과실행 시간메모리
235203ne4eHbKaGaraža (COCI17_garaza)C++17
160 / 160
2724 ms209508 KiB
//{ <defines> #include <bits/stdc++.h> using namespace std; //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,-O3") #define fr(i, n) for(int i = 0; i < n; ++i) #define fo(n) fr(i, n) #define re return #define ef else if #define ifn(x) if(!(x)) #define _ << ' ' << #define ft first #define sd second #define ve vector #define pb push_back #define eb emplace_back #define sz(x) int((x).size()) #define bnd(x) x.begin(), x.end() #define clr(x, y) memset((x), (y), sizeof (x)) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef ve<int> vi; inline ll time() {re chrono :: system_clock().now().time_since_epoch().count();} mt19937 rnd(time()); mt19937_64 RND(time()); template<typename t> inline void umin(t &a, t b) {a = min(a, b);} template<typename t> inline void umax(t &a, t b) {a = max(a, b);} int md = 998244353; inline int m_add(int&a, int b) {a += b; if(a < 0) a += md; if(a >= md) a -= md; re a;} inline int m_sum(int a, int b) {a += b; if(a < 0) a += md; if(a >= md) a -= md; re a;} inline int m_mul(int&a, int b) {re a = 1ll * a * b % md;} inline int m_prod(int a, int b) {re 1ll * a * b % md;} int m_bpow(ll A, ll b) { int a = A % md; ll ans = 1; for(ll p = 1ll << 63 - __builtin_clzll(b); p; p >>= 1) { (ans *= ans) %= md; if(p & b) (ans *= a) %= md; } re ans; } //const ld pi = arg(complex<ld>(-1, 0)); //const ld pi2 = pi + pi; const int oo = 2e9; const ll OO = 4e18; //} </defines> const int N = 3e5 + 5; int n, q; int a[N]; vi sieve() { vi primes; bool f[N] {}; for(int i = 2; i * i <= 1e9; ++i) { if(f[i]) continue; primes.pb(i); for(int j = i * i; j < N; j += i) f[j] = true; } re primes; } vi primes; inline void factorize(int v, list<pii> &f) { ifn(v) return; for(int i : primes) { if(i * i > v) break; if(!(v % i)) { f.pb({i, 1}); do v /= i; while(!(v % i)); } } if(v - 1) f.pb({v, 1}); } struct seg { list<pii> p, s; int gcd, len; ll ans; seg(): len(0) {} seg(int v) { list<int> f; factorize(v, p); s = p; gcd = v; len = 1; ans = v > 1; } }; typedef list<pii>::const_iterator lit; #define F (*fi) #define S (*se) seg operator+ (const seg &a, const seg &b) { if(!a.len) re b; if(!b.len) re a; seg n {}; n.gcd = __gcd(a.gcd, b.gcd); n.ans = a.ans + b.ans; n.len = a.len + b.len; lit fi = b.p.begin(); for(const pii &z : a.p) { n.p.pb(z); if(z.sd == a.len) { if(b.gcd % z.ft) { for(; fi != b.p.end() && F.ft < z.ft; ++fi); if(fi != b.p.end() && F.ft == z.ft) n.p.back().sd += F.sd; } else { n.p.back().sd += b.len; } } } lit se = a.s.begin(); for(const pii &z : b.s) { n.s.pb(z); if(z.sd == b.len) { if(a.gcd % z.ft) { for(; se != a.s.end() && S.ft < z.ft; ++se); if(se != a.s.end() && S.ft == z.ft) n.s.back().sd += S.sd; } else { n.s.back().sd += a.len; } } } fi = a.s.begin(), se = b.p.begin(); map< int, int, greater<int> > f; //cerr << "initial: " << n.ans << endl; //for(pii i : a.s) cerr << i.ft _ i.sd << endl; //cerr << endl; //for(pii i : b.p) cerr << i.ft _ i.sd << endl; //cerr << endl; while(fi != a.s.end() && se != b.p.end()) { if(F.ft == S.ft) { //cerr << F.ft _ F.sd _ S.ft _ S.sd << endl; umax(f[F.sd], S.sd); ++fi, ++se; } else F.ft < S.ft ? fi++ : se++; } //cerr << endl; int pr = -1, mx = 0; for(const pii &t : f) { if(~pr) n.ans += 1ll * mx * (pr - t.ft); pr = t.ft, umax(mx, t.sd); } n.ans += 1ll * mx * pr; //cerr << "final: " << n.ans << endl; //cerr << endl; re n; } struct tree { tree *l, *r; seg v; tree(int tl = 0, int tr = n - 1): l(r = 0), v() { if(tl < tr) { int tm = (tl + tr) >> 1; l = new tree(tl, tm); r = new tree(tm + 1, tr); v = l->v + r->v; } else { v = *new seg(a[tl]); } } void upd(int p, int x, int tl = 0, int tr = n - 1) { if(tl == tr) re void(v = *new seg(x)); int tm = (tl + tr) >> 1; p <= tm ? l->upd(p, x, tl, tm) : r->upd(p, x, tm + 1, tr); v = l->v + r->v; } seg req(int ql, int qr, int tl = 0, int tr = n - 1) { if(ql > qr) re *new seg(); if(tl == ql && tr == qr) re v; int tm = (tl + tr) >> 1; re l->req(ql, min(qr, tm), tl, tm) + r->req(max(tm + 1, ql), qr, tm + 1, tr); } }; void solve() { cin >> n >> q; fo(n) cin >> a[i]; primes = sieve(); tree t {}; while(q--) { int tp; cin >> tp; if(tp == 1) { int x, v; cin >> x >> v; t.upd(--x, v); } else { int l, r; cin >> l >> r; cout << t.req(--l, --r).ans << '\n'; } } } int main() { #ifdef _LOCAL freopen("in.txt", "r", stdin); int tests; cin >> tests; for(int test = 1; test <= tests; ++test) { cerr << "case #" << test << endl; solve(); cerr << endl; } #else // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); #endif return 0; }

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

garaza.cpp: In function 'int m_bpow(ll, ll)':
garaza.cpp:50:26: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
     for(ll p = 1ll << 63 - __builtin_clzll(b); p; p >>= 1) {
                       ~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...