Submission #379922

#TimeUsernameProblemLanguageResultExecution timeMemory
379922rocks03Lightning Rod (NOI18_lightningrod)C++14
100 / 100
803 ms227988 KiB
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int fast_read_int(){
    register int c, n = 0;
    do{
        c = getchar_unlocked();
    }while (c < '0' || c > '9');
    do{
        n = (n << 3) + (n << 1) + (c - '0');
        c = getchar_unlocked();
    }while (c >= '0' && c <= '9');
    return n;
}

void solve(){
    int N = fast_read_int();
    vector<int> x(N), y(N);
    rep(i, 0, N){
    	x[i] = fast_read_int();
      	y[i] = fast_read_int();
    }
    deque<int> q;
    q.push_back(0);
    rep(i, 1, N){
        while(SZ(q) && x[i] - y[i] <= x[q.back()] - y[q.back()])
            q.pop_back();
        q.push_back(i);
    }
    int ans = 0;
    while(SZ(q)){
        int v = q[0];
        q.front();
        ans++;
        while(SZ(q) && x[v] + y[v] >= x[q[0]] + y[q[0]]){
            q.pop_front();
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}
#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...