답안 #1098854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098854 2024-10-10T08:43:50 Z ducdev Global Warming (CEOI18_glo) C++14
10 / 100
59 ms 7840 KB
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) (x).begin(), (x).end()
 
typedef long long ll;
 
const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
 
int n;
ll a[MAX_N + 5], x;
 
struct FenwickTree {
    vector<int> bit;
    int n;
 
    void update(int pos, int val) {
        for (; pos <= n; pos += pos & (-pos))
            bit[pos] = max(bit[pos], val);
    };
 
    int get(int pos) {
        int ret = 0;
        for (; pos > 0; pos -= pos & (-pos))
            ret = max(ret, bit[pos]);
        return ret;
    };
 
    FenwickTree(int n) : n(n) {
        bit.assign(n + 5, 0);
    };
};
 
namespace SUBTASK_2 {
    const int N = MAX_N;
 
    ll c[N + 5];
 
    void Solve() {
        vector<ll> v;
        for (int i = 1; i <= n; i++) c[i] = a[i];
        for (int i = 1; i <= n; i++) v.push_back(c[i]);
 
        sort(all(v));
        v.resize(unique(all(v)) - v.begin());
 
        for (int i = 1; i <= n; i++) {
            c[i] = lower_bound(all(v), c[i]) - v.begin() + 1;
        };
 
        FenwickTree bit(n);
        int res = 0;
        for (int i = 1; i <= n; i++) {
            int dp = bit.get(c[i] - 1);
            bit.update(c[i], dp + 1);
            res = max(res, dp + 1);
        }
 
        cout << res << '\n';
    };
};  // namespace SUBTASK_2
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("MAIN.INP", "r")) {
        freopen("MAIN.INP", "r", stdin);
        freopen("MAIN.OUT", "w", stdout);
    };
 
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    };
 
        return SUBTASK_2::Solve(), 0;
};

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("MAIN.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("MAIN.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 7840 KB Output is correct
2 Correct 59 ms 7744 KB Output is correct
3 Correct 58 ms 7744 KB Output is correct
4 Correct 59 ms 7692 KB Output is correct
5 Correct 30 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2268 KB Output is correct
2 Correct 16 ms 2272 KB Output is correct
3 Correct 13 ms 2276 KB Output is correct
4 Incorrect 8 ms 2016 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 4060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -