Submission #164810

# Submission time Handle Problem Language Result Execution time Memory
164810 2019-11-23T14:14:08 Z mosiashvililuka Money (IZhO17_money) C++14
100 / 100
727 ms 93052 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,pas,f[1000009],read2[1000009],read[1000009],p[1000009],pi,mi=1000003,dp[1000009],fen[1000009];
vector <int> v[2000009];
vector <int>::iterator it;
void upd(int q, int w){
    while(q<=1000000){
        fen[q]+=w;
        q=q+(q&(-q));
    }
}
int readd(int q){
    if(q<=0) return 0;
    int jm=0;
    while(q>0){
        jm+=fen[q];
        q=q-(q&(-q));
    }
    return jm;
}
int main(){
    scanf("%d",&a);
    for(b=1; b<=a; b++){
        scanf("%d",&p[b]);
    }
    for(b=1; b<=a; b++){
        if(p[b]==p[b-1]) continue;
        pi++;
        f[pi]=p[b];
    }
    a=pi;
    for(b=1; b<=a; b++){
        upd(f[b],1);
        read[b]=readd(f[b]);
        read2[b]=readd(f[b]-1);
    }
    dp[0]=1;
    for(b=1; b<=a; b++){
        if(f[b]>=f[b-1]) dp[b]=dp[b-1]; else dp[b]=b;
    }
//    for(b=1; b<=1000000; b++) read[b]+=read[b-1];
/*    for(b=1; b<=a; b++) cout<<read[b]<<" ";
    return 0;*/
    for(b=1; b<=a; b++){
//        cout<<f[b]<<" ";
        //cout<<b<<" "<<read[b]-b+mi<<" "<<read2[b]-b+1+mi<<endl;
        v[read[b]-b+mi].push_back(b);
    }
  //  cout<<endl;
    b=a;
    while(b>0){
        //cout<<b<<endl;
        pas++;
        it=lower_bound(v[read2[b]-b+1+mi].begin(),v[read2[b]-b+1+mi].end(),dp[b]);
        if(it==v[read2[b]-b+1+mi].end()||(*it)>=b){
            b=b-1;
            continue;
        }
        b=(*it)-1;
    }
    cout<<pas;
    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&a);
     ~~~~~^~~~~~~~~
money.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[b]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 49 ms 47352 KB Output is correct
3 Correct 50 ms 47352 KB Output is correct
4 Correct 49 ms 47352 KB Output is correct
5 Correct 49 ms 47448 KB Output is correct
6 Correct 48 ms 47324 KB Output is correct
7 Correct 50 ms 47352 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 48 ms 47376 KB Output is correct
10 Correct 49 ms 47480 KB Output is correct
11 Correct 48 ms 47608 KB Output is correct
12 Correct 49 ms 47376 KB Output is correct
13 Correct 49 ms 47496 KB Output is correct
14 Correct 48 ms 47480 KB Output is correct
15 Correct 48 ms 47528 KB Output is correct
16 Correct 49 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 49 ms 47352 KB Output is correct
3 Correct 50 ms 47352 KB Output is correct
4 Correct 49 ms 47352 KB Output is correct
5 Correct 49 ms 47448 KB Output is correct
6 Correct 48 ms 47324 KB Output is correct
7 Correct 50 ms 47352 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 48 ms 47376 KB Output is correct
10 Correct 49 ms 47480 KB Output is correct
11 Correct 48 ms 47608 KB Output is correct
12 Correct 49 ms 47376 KB Output is correct
13 Correct 49 ms 47496 KB Output is correct
14 Correct 48 ms 47480 KB Output is correct
15 Correct 48 ms 47528 KB Output is correct
16 Correct 49 ms 47480 KB Output is correct
17 Correct 49 ms 47368 KB Output is correct
18 Correct 61 ms 47608 KB Output is correct
19 Correct 49 ms 47480 KB Output is correct
20 Correct 50 ms 47580 KB Output is correct
21 Correct 51 ms 47476 KB Output is correct
22 Correct 49 ms 47388 KB Output is correct
23 Correct 50 ms 47352 KB Output is correct
24 Correct 49 ms 47480 KB Output is correct
25 Correct 50 ms 47608 KB Output is correct
26 Correct 50 ms 47736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 49 ms 47352 KB Output is correct
3 Correct 50 ms 47352 KB Output is correct
4 Correct 49 ms 47352 KB Output is correct
5 Correct 49 ms 47448 KB Output is correct
6 Correct 48 ms 47324 KB Output is correct
7 Correct 50 ms 47352 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 48 ms 47376 KB Output is correct
10 Correct 49 ms 47480 KB Output is correct
11 Correct 48 ms 47608 KB Output is correct
12 Correct 49 ms 47376 KB Output is correct
13 Correct 49 ms 47496 KB Output is correct
14 Correct 48 ms 47480 KB Output is correct
15 Correct 48 ms 47528 KB Output is correct
16 Correct 49 ms 47480 KB Output is correct
17 Correct 49 ms 47368 KB Output is correct
18 Correct 61 ms 47608 KB Output is correct
19 Correct 49 ms 47480 KB Output is correct
20 Correct 50 ms 47580 KB Output is correct
21 Correct 51 ms 47476 KB Output is correct
22 Correct 49 ms 47388 KB Output is correct
23 Correct 50 ms 47352 KB Output is correct
24 Correct 49 ms 47480 KB Output is correct
25 Correct 50 ms 47608 KB Output is correct
26 Correct 50 ms 47736 KB Output is correct
27 Correct 50 ms 47356 KB Output is correct
28 Correct 50 ms 47388 KB Output is correct
29 Correct 49 ms 47480 KB Output is correct
30 Correct 50 ms 47480 KB Output is correct
31 Correct 50 ms 47352 KB Output is correct
32 Correct 51 ms 47452 KB Output is correct
33 Correct 50 ms 47480 KB Output is correct
34 Correct 50 ms 47480 KB Output is correct
35 Correct 49 ms 47352 KB Output is correct
36 Correct 49 ms 47352 KB Output is correct
37 Correct 51 ms 48644 KB Output is correct
38 Correct 51 ms 48656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 49 ms 47352 KB Output is correct
3 Correct 50 ms 47352 KB Output is correct
4 Correct 49 ms 47352 KB Output is correct
5 Correct 49 ms 47448 KB Output is correct
6 Correct 48 ms 47324 KB Output is correct
7 Correct 50 ms 47352 KB Output is correct
8 Correct 49 ms 47352 KB Output is correct
9 Correct 48 ms 47376 KB Output is correct
10 Correct 49 ms 47480 KB Output is correct
11 Correct 48 ms 47608 KB Output is correct
12 Correct 49 ms 47376 KB Output is correct
13 Correct 49 ms 47496 KB Output is correct
14 Correct 48 ms 47480 KB Output is correct
15 Correct 48 ms 47528 KB Output is correct
16 Correct 49 ms 47480 KB Output is correct
17 Correct 49 ms 47368 KB Output is correct
18 Correct 61 ms 47608 KB Output is correct
19 Correct 49 ms 47480 KB Output is correct
20 Correct 50 ms 47580 KB Output is correct
21 Correct 51 ms 47476 KB Output is correct
22 Correct 49 ms 47388 KB Output is correct
23 Correct 50 ms 47352 KB Output is correct
24 Correct 49 ms 47480 KB Output is correct
25 Correct 50 ms 47608 KB Output is correct
26 Correct 50 ms 47736 KB Output is correct
27 Correct 50 ms 47356 KB Output is correct
28 Correct 50 ms 47388 KB Output is correct
29 Correct 49 ms 47480 KB Output is correct
30 Correct 50 ms 47480 KB Output is correct
31 Correct 50 ms 47352 KB Output is correct
32 Correct 51 ms 47452 KB Output is correct
33 Correct 50 ms 47480 KB Output is correct
34 Correct 50 ms 47480 KB Output is correct
35 Correct 49 ms 47352 KB Output is correct
36 Correct 49 ms 47352 KB Output is correct
37 Correct 51 ms 48644 KB Output is correct
38 Correct 51 ms 48656 KB Output is correct
39 Correct 191 ms 62120 KB Output is correct
40 Correct 380 ms 78648 KB Output is correct
41 Correct 157 ms 60656 KB Output is correct
42 Correct 195 ms 61352 KB Output is correct
43 Correct 148 ms 57320 KB Output is correct
44 Correct 477 ms 85556 KB Output is correct
45 Correct 426 ms 84076 KB Output is correct
46 Correct 461 ms 85680 KB Output is correct
47 Correct 242 ms 74732 KB Output is correct
48 Correct 300 ms 79212 KB Output is correct
49 Correct 536 ms 90276 KB Output is correct
50 Correct 498 ms 88600 KB Output is correct
51 Correct 546 ms 91284 KB Output is correct
52 Correct 476 ms 89276 KB Output is correct
53 Correct 510 ms 89836 KB Output is correct
54 Correct 483 ms 87624 KB Output is correct
55 Correct 618 ms 93032 KB Output is correct
56 Correct 660 ms 92972 KB Output is correct
57 Correct 681 ms 92988 KB Output is correct
58 Correct 727 ms 92948 KB Output is correct
59 Correct 654 ms 93028 KB Output is correct
60 Correct 649 ms 93052 KB Output is correct
61 Correct 720 ms 92884 KB Output is correct
62 Correct 669 ms 92888 KB Output is correct