제출 #1291456

#제출 시각아이디문제언어결과실행 시간메모리
1291456dzhoz0Cloud Computing (CEOI18_clo)C++20
0 / 100
1 ms572 KiB
/*
    it could have been better :)
    it will next time ;)
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>

const int MOD = 1'000'000'000 + 7;

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    if (!name.empty())
    {
        freopen((name + ".INP").c_str(), "r", stdin);
        freopen((name + ".OUT").c_str(), "w", stdout);
    }
#endif
}

struct Compressor {
    vi v;
    int sz() { return (int)v.size(); }

    void add(int x) {
        v.push_back(x);
    }
    
    void init() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
    }

    int id(int key) {
        return lower_bound(v.begin(), v.end(), key) - v.begin() + 1;
    }
};

struct FenwickTree {
    int n;
    vi bit;
    FenwickTree(int sz) {
        n = sz;
        bit.resize(n + 1);
    }
    void upd(int id, int v) {
        while(id <= n) {
            bit[id] = max(bit[id], v);
            id += id & (-id);
        }
    }
    int query(int id) {
        int res = 0;
        while(id > 0) {
            res = max(res, bit[id]);
            id -= id & (-id);
        }
        return res;
    }

};

const int MAXN = 2e5;
int n, x;
int a[MAXN + 5]; 
int f1[MAXN + 5], f2[MAXN + 5];
void solve()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    {
        vi d;
        for(int i = 1; i <= n; i++) {
            int x = a[i];
            int id = lower_bound(d.begin(), d.end(), x) - d.begin();
            if(id == d.size()) d.push_back(x);
            else d[id] = x;
            f1[i] = id + 1;
        }
    }

    {
        vi d;
        for(int i = n; i >= 1; i--) {
            int x = -a[i];
            int id = lower_bound(d.begin(), d.end(), x) - d.begin();
            if(id == d.size()) d.push_back(x);
            else d[id] = x;
            f2[i] = id + 1;
        }
    }

    Compressor cmp;
    for(int i = 1; i <= n; i++) {
        cmp.add(a[i] - 1);
        cmp.add(a[i] - x);
    }
    cmp.init();
    FenwickTree bit(cmp.sz());
    int res = f1[n]; 
    for(int i = 1; i <= n; i++) {
        res = max(res, bit.query(cmp.id(a[i] - 1)) + f2[i]);
        bit.upd(cmp.id(a[i] - x), f1[i]);
    }
    cout << res << '\n';
    
}
signed main()
{
    setIO();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

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

clo.cpp: In function 'void setIO(std::string)':
clo.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".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...
#Verdict Execution timeMemoryGrader output
Fetching results...