답안 #44286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44286 2018-03-31T08:58:11 Z Extazy Money (IZhO17_money) C++17
100 / 100
283 ms 152484 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1000007;

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

void update(int pos, int val) {
    for(;pos<N;pos+=pos&(-pos)) it[pos]+=val;
}

int query(int pos) {
    int ans=0;
    for(;pos>=1;pos-=pos&(-pos)) ans+=it[pos];
    return ans;
}

int query(int l, int r) {
    return l>r ? 0 : query(r)-query(l-1);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j;

    scanf("%d", &n);
    for(i=1;i<=n;i++) {
        scanf("%d", &a[i]);
    }

    for(i=1;i<=n;) {
        ++ans;

        j=i;
        while(j+1<=n && a[j]<=a[j+1] && query(a[i]+1,a[j+1]-1)==0) {
            ++j;
        }

        for(;i<=j;i++) {
            update(a[i],1);
        }
    }

    printf("%d\n", ans);
    
    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
money.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 920 KB Output is correct
16 Correct 2 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 920 KB Output is correct
16 Correct 2 ms 920 KB Output is correct
17 Correct 2 ms 920 KB Output is correct
18 Correct 2 ms 920 KB Output is correct
19 Correct 2 ms 920 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 3 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 2 ms 1028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 920 KB Output is correct
16 Correct 2 ms 920 KB Output is correct
17 Correct 2 ms 920 KB Output is correct
18 Correct 2 ms 920 KB Output is correct
19 Correct 2 ms 920 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 3 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 2 ms 1028 KB Output is correct
27 Correct 2 ms 1028 KB Output is correct
28 Correct 2 ms 1028 KB Output is correct
29 Correct 2 ms 1028 KB Output is correct
30 Correct 2 ms 1028 KB Output is correct
31 Correct 2 ms 1028 KB Output is correct
32 Correct 2 ms 1028 KB Output is correct
33 Correct 2 ms 1028 KB Output is correct
34 Correct 2 ms 1028 KB Output is correct
35 Correct 2 ms 1028 KB Output is correct
36 Correct 2 ms 1028 KB Output is correct
37 Correct 3 ms 2028 KB Output is correct
38 Correct 3 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 920 KB Output is correct
16 Correct 2 ms 920 KB Output is correct
17 Correct 2 ms 920 KB Output is correct
18 Correct 2 ms 920 KB Output is correct
19 Correct 2 ms 920 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 3 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 2 ms 1028 KB Output is correct
27 Correct 2 ms 1028 KB Output is correct
28 Correct 2 ms 1028 KB Output is correct
29 Correct 2 ms 1028 KB Output is correct
30 Correct 2 ms 1028 KB Output is correct
31 Correct 2 ms 1028 KB Output is correct
32 Correct 2 ms 1028 KB Output is correct
33 Correct 2 ms 1028 KB Output is correct
34 Correct 2 ms 1028 KB Output is correct
35 Correct 2 ms 1028 KB Output is correct
36 Correct 2 ms 1028 KB Output is correct
37 Correct 3 ms 2028 KB Output is correct
38 Correct 3 ms 2156 KB Output is correct
39 Correct 112 ms 6128 KB Output is correct
40 Correct 164 ms 12808 KB Output is correct
41 Correct 78 ms 13668 KB Output is correct
42 Correct 83 ms 16012 KB Output is correct
43 Correct 59 ms 17168 KB Output is correct
44 Correct 263 ms 26908 KB Output is correct
45 Correct 201 ms 33508 KB Output is correct
46 Correct 208 ms 40332 KB Output is correct
47 Correct 266 ms 47152 KB Output is correct
48 Correct 194 ms 53936 KB Output is correct
49 Correct 239 ms 64728 KB Output is correct
50 Correct 227 ms 71400 KB Output is correct
51 Correct 225 ms 78148 KB Output is correct
52 Correct 276 ms 85128 KB Output is correct
53 Correct 226 ms 91868 KB Output is correct
54 Correct 203 ms 98276 KB Output is correct
55 Correct 236 ms 105080 KB Output is correct
56 Correct 263 ms 111912 KB Output is correct
57 Correct 231 ms 118640 KB Output is correct
58 Correct 233 ms 125396 KB Output is correct
59 Correct 272 ms 132052 KB Output is correct
60 Correct 260 ms 138872 KB Output is correct
61 Correct 283 ms 145668 KB Output is correct
62 Correct 235 ms 152484 KB Output is correct