Submission #1105823

# Submission time Handle Problem Language Result Execution time Memory
1105823 2024-10-28T03:12:52 Z QuocSensei Global Warming (CEOI18_glo) C++14
0 / 100
176 ms 10952 KB
#include <bits/stdc++.h>

#define ll long long
#define el cout << '\n'

using namespace std;

const int maxn = 4e5;

int n, bitUp[maxn + 10], bitDown[maxn + 10], lis[maxn + 10], ans = 0;
vector<ll> v;
ll x, a[maxn + 10];

void updateUp(int x, int v)
{
    for (;x <= maxn; x += x&-x) bitUp[x] = max(bitUp[x], v);
}
int getUp(int x)
{
    int ans = 0;
    for (;x ; x&=x-1) ans = max(ans, bitUp[x]);
    return ans;
}
void updateDown(int x, int v)
{
    for (;x; x&=x-1) bitDown[x] = max(bitDown[x], v);
}
int getDown(int x)
{
    int ans = 0;
    for (;x <= maxn; x += x&-x) ans = max(ans, bitDown[x]);
    return ans;
}
ll f(ll x)
{
    return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("GLO.INP", "r"))
    {
        freopen("GLO.INP", "r", stdin);
        freopen("GLO.OUT", "w", stdout);
    }
    cin >> n >> x;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        v.push_back(a[i]);
        v.push_back(a[i] + x);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (int i = n; i >= 1; i--)
    {
        int p = getDown(f(a[i]) + 1) + 1;
        lis[i] = p;
        updateDown(f(a[i]), p);
    }
    for (int i = 1; i <= n; i++)
    {
        int p = getUp(f(a[i] + x) - 1) + 1;
        int u = getUp(f(a[i])) + 1;
        ans = max(ans, p + lis[i] - 1);
        updateUp(f(a[i]), u);
    }
    cout << ans;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("GLO.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("GLO.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 10952 KB Output is correct
2 Correct 159 ms 10952 KB Output is correct
3 Correct 160 ms 10952 KB Output is correct
4 Correct 154 ms 10952 KB Output is correct
5 Incorrect 65 ms 10952 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 6320 KB Output is correct
2 Correct 45 ms 6348 KB Output is correct
3 Correct 40 ms 6380 KB Output is correct
4 Incorrect 18 ms 5840 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 7884 KB Output is correct
2 Correct 81 ms 7884 KB Output is correct
3 Correct 176 ms 10952 KB Output is correct
4 Incorrect 69 ms 10952 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -