Submission #1305324

#TimeUsernameProblemLanguageResultExecution timeMemory
1305324_TemirhanBouquet (EGOI24_bouquet)C++20
100 / 100
98 ms20192 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>  
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector")
#pragma GCC target("avx2,fma,tune=native")
#pragma clang loop vectorize(enable)
#pragma clang loop interleave(enable)
#endif

#define int long long
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;

void file( string s = "" )
{
    if( s.empty() )
        return;
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int N = 2e5 + 2;
const int N1 = 1e6 + 2;
const int inf = 1e9 + 2;
const int INF = 1e18 + 2;
const int mod = 1e9 + 7;
int T = 1, t[4 * N];

void upd( int v, int tl, int tr, int p, int x )
{
    if( tl == tr )
    {
        t[v] = max(t[v], x);
        return;
    }
    int m = (tl + tr) / 2;
    if( p <= m )
        upd(v + v, tl, m, p, x);
    else
        upd(v + v + 1, m + 1, tr, p, x);
    t[v] = max(t[v + v], t[v + v + 1]);
}

int get( int v, int tl, int tr, int l, int r )
{
    if( r < tl || tr < l )
        return 0;
    if( l <= tl && tr <= r )
        return t[v];
    int m = (tl + tr) / 2;
    return max(get(v + v, tl, m, l, r), get(v + v + 1, m + 1, tr, l, r));
}

void solve()
{
    int n;
    cin >>n;
    int l[n + 1], r[n + 1];
    vector< int > dp(n + 1), v[n + 1];
    for( int i = 1; i <= n; ++i )
    {
        cin >>l[i] >>r[i];
        l[i] = max(1ll, i - l[i]);
        r[i] = min(n, i + r[i]);
        v[r[i]].pb(i);
    }
    int ans = 0;
    for( int i = 1; i <= n; ++i )
    {
        int x = 0;
        if( l[i] > 1 )
            x = get(1, 1, n, 1, l[i] - 1);
        dp[i] = x + 1;
        for( auto j: v[i] )
            upd(1, 1, n, j, dp[j]);
    }
    for( int i = 1; i <= n; ++i )
        ans = max(ans, dp[i]);
    cout <<ans;
}

signed main()
{
    file("");
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin >>T;
    while( T-- )
        solve();
}

Compilation message (stderr)

Main.cpp: In function 'void file(std::string)':
Main.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...