제출 #1282783

#제출 시각아이디문제언어결과실행 시간메모리
1282783herominhsteveGlobal Warming (CEOI18_glo)C++20
100 / 100
112 ms7604 KiB
#include <bits/stdc++.h>
#define el '\n'
#define FNAME "USB"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,n) memset(x,(n),sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9 + 7;
template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;}
template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;}

void setup(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	if (fopen(FNAME".inp","r")){
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

template<typename T>
struct FenwickTree{
    int n;
    vector<T> bit;
    FenwickTree(int N=0){
        n=N;
        if (n>0){
            bit.resize(n+1,0);
        }
    }
    void update(int node,T val){
        while (node<=n){
            maximize(bit[node],val);
            node += (node & -node);
        }
    }
    T getVal(int node){
        T res=0;
        while (node>0){
            maximize(res,bit[node]);
            node -= (node & -node);
        }
        return res;
    }
};

int n,X,m;
vector<int> a;
vector<int> compress;

void init(){
	cin>>n>>X;
    a.resize(n);
    for (int &x : a){
        cin>>x;
        compress.push_back(x);
        compress.push_back(x+X);
    }
    sort(allof(compress));
    compress.resize(unique(allof(compress))-compress.begin());
    m = compress.size();
}

inline int getID(int x){
    return lower_bound(allof(compress),x) - compress.begin() + 1;
}

void sol(){
	// ? dp[0/1]: LIS ending at i, 1 = has modified
    vector<FenwickTree<int>> dp(2,FenwickTree<int>(m));

    int res = 1;
    for (const int &x : a){
        int ID = getID(x);
        int dp0 = dp[0].getVal(ID-1) + 1;
        int dp1 = dp[1].getVal(ID-1) + 1;
        int addID = getID(x + X);
        if (addID>=1) maximize(dp1, dp[0].getVal(addID-1) + 1);
        dp[0].update(ID,dp0);
        dp[1].update(ID,dp1);
        maximize(res,max(dp0,dp1));
    }
    cout<<res;
}

int main(){
    setup();
    init();
    sol();
}

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

glo.cpp: In function 'void setup()':
glo.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |                 freopen(FNAME".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 freopen(FNAME".out","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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...