제출 #38269

#제출 시각아이디문제언어결과실행 시간메모리
38269Just_Solve_The_ProblemMoney (IZhO17_money)C++11
100 / 100
296 ms9828 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e6 + 7;

int a[N], tree[N], n, ans;

void upd (int pos) {
    for (; pos < N; pos += pos & -pos) {
        tree[pos]++;
    }
}

int get (int r) {
    int res = 0;
    for (; r > 0; r -= r & -r) {
        res += tree[r];
    }
    return res;
}

main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", &a[i]);
    }
    for (int i = 2, pos = 1; i <= n; i++) {
        if (a[i - 1] > a[i] || get(a[i] - 1) - get(a[pos]) > 0) {
            ans++;
            while (pos < i) upd(a[pos++]);
        }
    }
    cout << ans + 1;
}

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

money.cpp:23:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
money.cpp: In function 'int main()':
money.cpp:24:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d", &n);
                     ^
money.cpp:26:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &a[i]);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...