Submission #1331774

#TimeUsernameProblemLanguageResultExecution timeMemory
1331774ilovewaguriGlobal Warming (CEOI18_glo)C++20
100 / 100
145 ms9168 KiB
#include<bits/stdc++.h>
using namespace std;
#define NAME "TEST"
#define nl '\n'
#define allofa(x,sz) x+1,x+sz+1
#define allof(x) x.begin(),x.end()
#define mset(x,val) memset(x,val,sizeof(x))
template<typename T> T Max(T x, T y){return(x>y)?x:y;};
template<typename T> T Min(T x, T y){return(x<y)?x:y;};
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;};
typedef long long ll;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e18;
const int INF = (int)1e9;
const int MAXN = (int)2e5+5;
int lis[MAXN],lds[MAXN];
int a[MAXN];
int n,x;

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

struct FenwickTree {
    int n;
    vector<int> fen;

    FenwickTree(int N = 0) {
        n=N;if(n>0) {
            fen.assign(n+4,0);
        }
    }

    void update(int node, int val) {
        while(node<=n) {
            maximize(fen[node],val);
            node+=(node & -node);
        }
    }

    int getVal(int node) {
        int res = 0;
        while(node>0) {
            maximize(res,fen[node]);
            node-=(node & -node);
        }
        return res;
    }
} fen,flis,flds;

signed main() {
    ccps();
    cin >> n >> x;
    vector<int> comp;
    for (int i = 1; i<=n; i++) {
        cin >> a[i];
        comp.push_back(a[i]);
        comp.push_back(a[i]-x);
    }
    sort(allof(comp));
    comp.resize(unique(allof(comp))-comp.begin());
    int m = (int)comp.size();
    fen = FenwickTree(m);
    flis = FenwickTree(m);
    flds = FenwickTree(m);
    int res = 1;
    for (int i = 1; i<=n; i++) {
        int pos = lower_bound(allof(comp),a[i])-comp.begin()+1;
        lis[i] = flis.getVal(pos-1)+1;
        flis.update(pos,lis[i]);
    }
    for (int i = n; i>=1; i--) {
        int pos = lower_bound(allof(comp),a[i])-comp.begin()+1;
        int posI = lower_bound(allof(comp),a[i]-x)-comp.begin()+1;
        pos = m-pos+1; posI = m-posI;
        lds[i] = flds.getVal(pos-1)+1;
        flds.update(pos,lds[i]);
        int best = fen.getVal(posI);
        maximize(res,lis[i]+best);
        fen.update(pos,lds[i]);
    }
    cout << res;
}

Compilation message (stderr)

glo.cpp: In function 'void ccps()':
glo.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(NAME".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...