제출 #405159

#제출 시각아이디문제언어결과실행 시간메모리
405159FalconMoney (IZhO17_money)C++17
100 / 100
1272 ms65892 KiB
#include <bits/stdc++.h>

#ifdef DEBUG
#include "debug.hpp"
#endif

using namespace std;

#define all(c)              (c).begin(), (c).end()
#define rall(c)             (c).rbegin(), (c).rend()
#define traverse(c, it)     for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N)           for(int i = 0; i < (N); ++i)
#define rrep(i, N)          for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N)          for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e)       for(int i = (s); i <= (e); ++i)

#ifdef DEBUG
#define debug(x...)         { \
                            ++dbg::depth; \
                            string dbg_vals = dbg::to_string(x); \
                            --dbg::depth; \
                            dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
                            }

#define light_debug(x)      { \
                            dbg::light = true; \
                            dbg::dout << __func__ << ":" << __LINE__; \
                            dbg::dout << "  " << #x << " = " << x << endl; \
                            dbg::light = false; \
                            }

#else
#define debug(x...)         42
#define light_debug(x)      42
#endif


using ll = long long;

template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }

template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }

class fenwick_tree {
        
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    reverse(all(a)); rep(i, n) a[i] = 1000000 - a[i];
    map<int, int> m;
    vector<int> x(n), y(n);
    rrep(i, n) {
        auto p = m.lower_bound(a[i]);
        x[i] = p == m.end() ? n : p->second;
        p = m.upper_bound(a[i]);
        y[i] = p == m.end() ? n : p->second;
        m[a[i]] = i;
    }

    debug(a, x, y);

    int c{};
    for(int i{}; i < n;) {
        int j{i};
        ++c;
        while(j + 1 < n && a[j + 1] == a[i]) ++j;
        if(j + 1 == y[j]) {
            ++j;
            while(j + 1 < n && j + 1 == x[j]) ++j;
        }
        debug(i, j);
        i = j + 1;
    }

    cout << c << '\n';
    
    
    #ifdef DEBUG
    dbg::dout << "\nExecution time: "
              << clock() * 1000 / CLOCKS_PER_SEC 
              << "ms" << endl;
    #endif
    return 0;
}

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

money.cpp: In function 'int main()':
money.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
money.cpp:67:5: note: in expansion of macro 'debug'
   67 |     debug(a, x, y);
      |     ^~~~~
money.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
money.cpp:78:9: note: in expansion of macro 'debug'
   78 |         debug(i, j);
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...