제출 #1293422

#제출 시각아이디문제언어결과실행 시간메모리
1293422yf_yusufAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
578 ms43920 KiB
//```// YF YUSUF // #include <bits/stdc++.h> #include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <algorithm> #include <cmath> #include <numeric> #include <queue> #include <stack> #include <cassert> #include <climits> #include <string> #include <cstdlib> #include <random> #include <iomanip> #include <ctime> using namespace std; #ifdef YF_CHECK bool LOCAL = 1; #else #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("O3") bool LOCAL = 0; #endif using i128 = __int128; using ll = long long; using ld = long double; using vll = vector <ll>; using mll = map <ll,ll>; using pll = pair <ll,ll>; using vvl = vector <vll>; using vpll = vector <pll>; template<class T>T MIN(T&a,T b){a=min(a,b);return a;} template<class T>T MAX(T&a,T b){a=max(a,b);return a;} #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sgr v+v+1,(tl+tr)/2+1,tr #define sgl v+v,tl,(tl+tr)/2 #define pb push_back #define ins insert #define S second #define F first mt19937_64 MT(time(0)); ll BP(ll a,ll b,ll mod=1e9+7){ if(b==0)return 1; ll q=BP(a,b/2,mod); return ((q*q)%mod*(b%2?a:1ll))%mod; } ll f(ll x){return x*(x+1)/2;} ll dup(ll a,ll b){return (a+b-1)/b;} ll lcm(ll a,ll b){return a/__gcd(a,b)*b;} ll invf(ll x){return (-1+sqrt(1+8*x))/2;} ll lg(ll x){return (x ? 63 - __builtin_clzll(x) : -1);} const ll mod=998244353; const ll INF=1e18; const ll inf=1e9+7; const ll N =1e6+7; ll n; vll x[N]; ll a[N], b[N]; int t1[N * 4], t2[N * 4]; void build (int v = 1, int tl = 1, int tr = n) { t1[v] = inf; t2[v] = -inf; if (tl == tr) { return; } int tm = tl + tr >> 1; build(v << 1, tl, tm); build(v << 1 | 1, tm + 1, tr); } int get1 (int l, int r, int v = 1, int tl = 1, int tr = n) { if (l > r) return inf; if (tl == l && tr == r) return t1[v]; int tm = tl + tr >> 1; return min(get1(l, min(r, tm), v << 1, tl, tm), get1(max(tm + 1, l), r, v << 1 | 1, tm + 1, tr)); } int get2 (int l, int r, int v = 1, int tl = 1, int tr = n) { if (l > r) return -inf; if (tl == l && tr == r) return t2[v]; int tm = tl + tr >> 1; return max(get2(l, min(r, tm), v << 1, tl, tm), get2(max(tm + 1, l), r, v << 1 | 1, tm + 1, tr)); } void upd1 (int pos, int val, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t1[v] = val; return; } int tm = tl + tr >> 1; if (pos <= tm) upd1(pos, val, v << 1, tl, tm); else upd1(pos, val, v << 1 | 1, tm + 1, tr); t1[v] = min(t1[v << 1], t1[v << 1 | 1]); } void upd2 (int pos, int val, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t2[v] = val; return; } int tm = tl + tr >> 1; if (pos <= tm) upd2(pos, val, v << 1, tl, tm); else upd2(pos, val, v << 1 | 1, tm + 1, tr); t2[v] = max(t2[v << 1], t2[v << 1 | 1]); } bool compX(const vll &a, const vll &b){ if(a[0] == b[0])return a[1] < b[1]; return a[0] < b[0]; } bool compE(const vll &a, const vll &b){ return a[1] < b[1]; } bool compI(const vll &a, const vll &b){ return a[2] < b[2]; } void YF_MAIN(ll TEST){ cin>>n; ll ans = 0; for(int i=1;i<=n;i++){ x[i] = {0, 0, 0}; cin>>x[i][0]>>x[i][1]; } sort(x+1, x+n+1, compX); for(int i=1;i<=n;i++){ x[i][2] = i; a[i] = (x[i][1] - x[i][0]); b[i] = (x[i][1] + x[i][0]); } build(); sort(x+1, x+n+1, compE); for(int j=n; j>=1; j--){ ll X = x[j][0]; ll E = x[j][1]; ll i = x[j][2]; bool ok = 1; // cout<<get1(i, n)<<" "<<get2(1, i)<<", "; if(X - E >= get1(i, n)) ok = 0; if(X + E <= get2(1, i)) ok = 0; if(ok) ans++; upd1(i, X - E); upd2(i, X + E); } cout<<ans; } const bool TECT=0; const bool FLSH=1; const ll SN=1e0 + 7; ll SM[SN]; const ll FN=1e0 + 7; ll FACT[FN], inv[FN], FMOD=inf; ll PER(ll n,ll k){return FACT[n] *inv[n-k]%FMOD;} ll CNK(ll n,ll k){return PER(n,k)*inv[k ]%FMOD;} void BEFORE(){ for(ll i=2;i<SN;i++){ if(SM[i])continue; for(ll j=i;j<SN;j+=i) MAX(SM[j],i); } FACT[0]=inv[0]=1; for(int i=1;i<FN;i++){ FACT[i]=FACT[i-1]*i%FMOD; inv[i]=BP(FACT[i],FMOD-2,FMOD); } } signed main(){ // freopen(("input.txt"),"r",stdin);freopen(("output.txt"),"w",stdout); if(FLSH){ ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(0); cout.tie(0); cin.tie(0); } cout<<(0 && LOCAL ? "\nYF_OUTPUT:\n\n" : ""); int TEST=1; if(TECT) cin>>TEST; BEFORE(); for(int T=1;T<=TEST;T++){ // cout<<"Case "<<T<<": "; YF_MAIN(T); cout<<(T==TEST ? "" : "\n"); } return 0; } // YF YUSUF ```
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...