답안 #1091550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091550 2024-09-21T08:18:09 Z guymmk Bouquet (EGOI24_bouquet) C++14
0 / 100
58 ms 20968 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("popcnt")
#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define pii pair<int,int>
#define debug(...) printf(__VA_ARGS__)
//#define debug(...)
#define trace(x) cout<<#x<<"="<<x<<endl;
//#define trace(x)
#define vi vector<int>
#define popcnt(x) (int)__builtin_popcount(x)
#define vpii vector<pii >
#define vvi vector<vector<int> >
#define umap unordered_map
#define uset unordered_set
#define mk make_pair
#define pb push_back
#define pob pop_back
#define _ <<' '<<
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define read(x) for (auto& zu: (x)) cin >> zu;
#define write(x) for (auto& zu: (x))cout << zu<<' '; cout<<endl;
static inline void print(const int &x) {
    if (x > 9)print(x / 10);
    putchar('0' + x % 10);
}

#define F first
#define S second
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define mustawa ios::sync_with_stdio(false);cin.tie(nullptr);
#define mishari main
const int inf=1e9+7;
void fa(bool ok){ cout << (ok ? "YES": "NO") << endl;}
int pw(ll a, ll b, ll mod= 1e9 + 7){
    ll result = 1;
    while(b) {
        if(b&1) {
            result = (result*a)%mod;
        }
        a = (a * a) % mod;
        b>>=1;
    }
    return result;
}
inline void usaco(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}int gcd(int a,int b){
    if (b == 0)return a;
    return gcd(b, a % b);
}

int lcm(int a, int b){
    return (a / gcd(a, b)) * b;
}
//long double log(int base,int x){
//    return log2(x)/log(base);
//}
int log(int base,int x){
    return (int)(log2(x)/log(base));
}
void vod(){}
int sum(int l,int r){
    if(l>r)swap(l,r);
    int a=((l-1)*(l))/2;
    int b=(r*(r+1))/2;
    return b-a;
}
struct SEG{
    int off;
    vi tree;
    SEG(int n){
        off=exp2((int) ceil(log2(n)));
        tree.resize(off*2);
    }
    void update(int i,int x){
        tree[i+=off]=x;
        while(i/=2)tree[i]=max(tree[i*2],tree[i*2+1]);
    }int _query(int i,int l,int r,int lo,int hi){
        if(l>=lo&&r<=hi)return tree[i];
        if(l>hi||r<lo)return 0;
        int md=l+(r-l)/2;
        return max(_query(i*2,l,md,lo,hi), _query(i*2+1,md+1,r,lo,hi));
    }int query(int l,int r){
        return _query(1,0,off,l,r);
    }
};
int L[(int)2e5+5],R[(int)(2e5+5)],dp[(int)2e5+5],n;
void solve(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>L[i]>>R[i];
    SEG seg=SEG(n);
    vi u[n];
    for(int i=0;i<n;i++){
        if(R[i]+i<n)u[R[i]+i].pb(i);
        dp[i]=1+seg.query(0,i-L[i]-1);
        for(auto j:u[i])seg.update(j,dp[j]);
    }
    int mx=0;
    for(int i=0;i<n;i++)mx=max(mx,dp[i]);
    cout<<mx<<endl;
}
signed mishari() {
    mustawa;
    //usaco("nocross");
    int tescases = 1;
    //cin>>tescases;
    for (int i = 1; i <= tescases; i++) {
        //cout<<"Case "<<i<<":"<<endl;
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 54 ms 20968 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 20808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 20816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 54 ms 20968 KB Output isn't correct
3 Halted 0 ms 0 KB -