제출 #754381

#제출 시각아이디문제언어결과실행 시간메모리
754381phongcdGlobal Warming (CEOI18_glo)C++17
0 / 100
2 ms340 KiB
#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 4e5 + 2;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int base = 311;
const int BLOCK_SIZE = 2000;
 
int n, x;

struct tree {
    int bit[N] = {0};
    void upd(int idx, int v) {
        for (; idx <= 2 * n; idx += idx & -idx)
            bit[idx] = max(bit[idx], v);
    }

    int get(int idx) {
        int ans = 0;
        for (; idx > 0; idx -= idx & -idx)
            ans = max(ans, bit[idx]);
        return ans;
    }
} bit0, bit1;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
    #endif
 
    cin >> n >> x;
    vector <int> a(n), b;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        b.push_back(a[i]);
        b.push_back(a[i] + x);
    }

    sort(all(b));
    b.erase(unique(all(b)), b.end());
    for (int i = 0; i < n; i ++) {
        int ac = lower_bound(all(b), a[i] + x) - b.begin() + 1;
        a[i] = lower_bound(all(b), a[i]) - b.begin() + 1;
        
        int res = bit0.get(a[i] - 1) + 1;
        int res2 = max(bit0.get(ac - 1), bit1.get(a[i] - 1)) + 1;

        bit0.upd(a[i], res);
        bit1.upd(a[i], res2);
    }

    cout << bit1.get(2 * n);
} 
/*
     /\_/\ zzZ
    (= -_-)
    / >u  >u
*/

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

glo.cpp: In function 'int main()':
glo.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:36:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(file".inp","r",stdin); freopen(file".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...