답안 #85039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85039 2018-11-18T10:09:50 Z igzi Money (IZhO17_money) C++17
100 / 100
436 ms 16268 KB
#include <bits/stdc++.h>
#define maxN 1000005

using namespace std;

int a[maxN],ans,tmp,d,n,i,f[maxN];

void update(int p,int v){
while(p<maxN){
    f[p]+=v;
    p+=p & (-p);
}
}

int query(int p){
int ans=0;
while(p>0){
    ans+=f[p];
    p-=p & (-p);
}
return ans;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=0;i<n;i++) {cin>>a[i]; update(a[i],1);}
    d=n-1;
    ans=1;
    for(i=n-1;i>0;i--){
        update(a[i],-1);
        if(a[i-1]>a[i]){d=i-1; ans++; continue;}
        if(a[i]==a[i-1]) continue;
        tmp=query(a[d]-1)-query(a[i-1]);
        if(tmp==0) continue;
        d=i-1;
        ans++;
    }
    sort(a,a+n);
    //for(i=0;i<n;i++) cout<<a[i]<<" ";
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 3 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 3 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 3 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 3 ms 784 KB Output is correct
17 Correct 2 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 2 ms 784 KB Output is correct
20 Correct 2 ms 784 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 788 KB Output is correct
23 Correct 2 ms 788 KB Output is correct
24 Correct 2 ms 788 KB Output is correct
25 Correct 2 ms 804 KB Output is correct
26 Correct 2 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 3 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 3 ms 784 KB Output is correct
17 Correct 2 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 2 ms 784 KB Output is correct
20 Correct 2 ms 784 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 788 KB Output is correct
23 Correct 2 ms 788 KB Output is correct
24 Correct 2 ms 788 KB Output is correct
25 Correct 2 ms 804 KB Output is correct
26 Correct 2 ms 820 KB Output is correct
27 Correct 2 ms 820 KB Output is correct
28 Correct 2 ms 820 KB Output is correct
29 Correct 2 ms 820 KB Output is correct
30 Correct 9 ms 836 KB Output is correct
31 Correct 2 ms 836 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 868 KB Output is correct
35 Correct 2 ms 868 KB Output is correct
36 Correct 2 ms 868 KB Output is correct
37 Correct 3 ms 1904 KB Output is correct
38 Correct 3 ms 2036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 3 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 3 ms 784 KB Output is correct
17 Correct 2 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 2 ms 784 KB Output is correct
20 Correct 2 ms 784 KB Output is correct
21 Correct 2 ms 788 KB Output is correct
22 Correct 2 ms 788 KB Output is correct
23 Correct 2 ms 788 KB Output is correct
24 Correct 2 ms 788 KB Output is correct
25 Correct 2 ms 804 KB Output is correct
26 Correct 2 ms 820 KB Output is correct
27 Correct 2 ms 820 KB Output is correct
28 Correct 2 ms 820 KB Output is correct
29 Correct 2 ms 820 KB Output is correct
30 Correct 9 ms 836 KB Output is correct
31 Correct 2 ms 836 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 868 KB Output is correct
35 Correct 2 ms 868 KB Output is correct
36 Correct 2 ms 868 KB Output is correct
37 Correct 3 ms 1904 KB Output is correct
38 Correct 3 ms 2036 KB Output is correct
39 Correct 111 ms 6012 KB Output is correct
40 Correct 188 ms 11504 KB Output is correct
41 Correct 91 ms 11504 KB Output is correct
42 Correct 85 ms 11504 KB Output is correct
43 Correct 61 ms 11504 KB Output is correct
44 Correct 246 ms 12428 KB Output is correct
45 Correct 219 ms 12428 KB Output is correct
46 Correct 225 ms 12488 KB Output is correct
47 Correct 187 ms 12488 KB Output is correct
48 Correct 212 ms 12488 KB Output is correct
49 Correct 291 ms 16140 KB Output is correct
50 Correct 303 ms 16140 KB Output is correct
51 Correct 311 ms 16260 KB Output is correct
52 Correct 285 ms 16260 KB Output is correct
53 Correct 296 ms 16260 KB Output is correct
54 Correct 298 ms 16260 KB Output is correct
55 Correct 336 ms 16268 KB Output is correct
56 Correct 364 ms 16268 KB Output is correct
57 Correct 435 ms 16268 KB Output is correct
58 Correct 436 ms 16268 KB Output is correct
59 Correct 335 ms 16268 KB Output is correct
60 Correct 369 ms 16268 KB Output is correct
61 Correct 373 ms 16268 KB Output is correct
62 Correct 380 ms 16268 KB Output is correct