Submission #340039

# Submission time Handle Problem Language Result Execution time Memory
340039 2020-12-26T15:48:37 Z Sprdalo Money (IZhO17_money) C++17
100 / 100
197 ms 15084 KB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

//Slozenost O(log n)

template<class T, int size>
struct fenwick {
    T a[size];
    /* precondition: pos > 0 */
    void add(int pos, const T& val) {
        while (pos < size) {
            a[pos] += val;
            pos += pos & -pos;
        }
    }
    T sum(int pos) {
        T ret = T();
        while (pos > 0) {
            ret += a[pos];
            pos -= pos & -pos;
        }
        return ret;
    }
};
fenwick<int, 1000010> drvo;
 
signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    
 
    int n;
    cin >> n;
 
    int a[n];
    for (auto& i : a){
        cin >> i;
    }
 
    int l = 0, r = 1, sol = 1;
    while(1){
        if (r == n) break;
 
        if (a[r] < a[r-1]){
 
            for (int i = l; i < r; ++i)
                drvo.add(a[i], 1);
 
            ++sol;
            l = r;
            r++;
            drvo.add(a[l], 1);
            continue;
        }
 
        if (a[l]+1 > a[r]-1){
            ++r;
            continue;
        }
 
        int x = drvo.sum(a[r]-1) - drvo.sum(a[l]);
        if (!x){
            ++r;
            continue;
        }
 
        for (int i = l; i < r; ++i)
            drvo.add(a[i], 1);
        l = r;
        ++sol;
        ++r;
    }
 
    cout<< sol << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 1644 KB Output is correct
38 Correct 1 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 1644 KB Output is correct
38 Correct 1 ms 1772 KB Output is correct
39 Correct 68 ms 2284 KB Output is correct
40 Correct 117 ms 3564 KB Output is correct
41 Correct 56 ms 1900 KB Output is correct
42 Correct 52 ms 1920 KB Output is correct
43 Correct 36 ms 1516 KB Output is correct
44 Correct 146 ms 4460 KB Output is correct
45 Correct 145 ms 4332 KB Output is correct
46 Correct 145 ms 4572 KB Output is correct
47 Correct 135 ms 4332 KB Output is correct
48 Correct 137 ms 4332 KB Output is correct
49 Correct 155 ms 8172 KB Output is correct
50 Correct 160 ms 8172 KB Output is correct
51 Correct 155 ms 8172 KB Output is correct
52 Correct 151 ms 8336 KB Output is correct
53 Correct 155 ms 8156 KB Output is correct
54 Correct 159 ms 8172 KB Output is correct
55 Correct 170 ms 8300 KB Output is correct
56 Correct 165 ms 8172 KB Output is correct
57 Correct 168 ms 8300 KB Output is correct
58 Correct 166 ms 8172 KB Output is correct
59 Correct 196 ms 14828 KB Output is correct
60 Correct 171 ms 15084 KB Output is correct
61 Correct 172 ms 14956 KB Output is correct
62 Correct 197 ms 14828 KB Output is correct