Submission #320903

# Submission time Handle Problem Language Result Execution time Memory
320903 2020-11-10T08:02:29 Z egas Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 54476 KB
#include <bits/stdc++.h>

using namespace std;

template < typename third >

class SegmentTree {

private:

    third *Stree;

    third *Snum;

    long n;

    third NullValue = 0;

    third combine(third a, third b) {

        return max(a,b);

    }

    void build(long idx, long s, long e) {

        if (s > e)

            return;

        if (s == e) {

            Stree[idx] = Snum[s];

            return ;

        }

        long m = ( s + e ) / 2;

        build( 2 * idx, s, m);

        build( 2 * idx + 1, m + 1, e);

        Stree[idx] = combine(Stree[2 * idx], Stree[2 * idx + 1] );

        return;

    }

    third queryUtil(long idx, long s, long e, long l, long r) {

        if (l > e || r < s)

            return NullValue;

        if (s >= l && e <= r) {

            return Stree[idx];

        }

        long m = ( s + e ) / 2;

        third left = queryUtil(2 * idx, s, m, l, r);

        third right = queryUtil(2 * idx + 1, m + 1, e, l, r);

        return combine(left, right );

    }

public:

    SegmentTree(vector<third> a) {

        this->n = a.size();

        Stree = new third[4 * n + 5];

        Snum = new third[n];

        for (long i = 0; i < n; i++) {

            Snum[i] = a[i];

        }

        build(1, 0, n - 1);

    }

    third query(long l, long r) {

        return queryUtil(1, 0, n - 1, l - 1, r - 1);

    }

};

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long n;

    cin >> n;

    long m;

    cin >> m;

    vector<long> a(n);

    for(long i = 0 ; i < n ; i++) {

        cin >> a[i];

    }

    vector<long> b(m);

    for(long i = 0 ; i < m ; i++) {

        cin >> b[i];

    }

    vector<long> diff(1000005,0);

    SegmentTree<long> ST(a);

    long *last=new long[1000005];

    for(long i = 0 ; i < a.size() ; i++) {

        last[a[i]]=-1;

    }

    for(long i=0; i<n; i++) {

        long ryt=0;

        long l=i;

        long r=a.size()-1;

        while(l<=r) {

            if(l==r) {

                if(ST.query(i+1,l+1)<=a[i]) {

                    ryt=max(ryt,l);

                }

                break;

            }

            long m=(l+r)/2;

            if(ST.query(i+1,m+1)>a[i]) {

                r=m-1;

            } else {

                l=m+1;

                ryt=max(ryt,m);

            }

        }

        ryt=ryt-i+1;

        ryt--;

        long left=1e9;

        l=last[a[i]]+1;

        r=i;

        while(l<=r) {

            if(l==r) {

                if(ST.query(l+1,i+1)<=a[i]) {

                    left=min(left,l);

                }

                break;

            }

            long m=(l+r)/2;

            if(ST.query(m+1,i+1)>a[i]) {

                l=m+1;

            } else {

                r=m-1;

                left=min(left,m);

            }

        }

        left=i-left;

        last[a[i]]=i;

        diff[a[i]]+=((left+1)*(ryt+1));

    }

    for(long i=1; i<diff.size(); i++) {

        diff[i]+=diff[i-1];

    }

    for(long i = 0 ; i < b.size() ; i++) {

        cout << diff[b[i]] << '\n';

    }

    return 0;

}

Compilation message

pilot.cpp: In function 'int32_t main()':
pilot.cpp:137:24: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |     for(long i = 0 ; i < a.size() ; i++) {
      |                      ~~^~~~~~~~~~
pilot.cpp:229:20: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  229 |     for(long i=1; i<diff.size(); i++) {
      |                   ~^~~~~~~~~~~~
pilot.cpp:235:24: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  235 |     for(long i = 0 ; i < b.size() ; i++) {
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 9 ms 8172 KB Output is correct
12 Correct 9 ms 8300 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8300 KB Output is correct
15 Correct 8 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 9 ms 8172 KB Output is correct
12 Correct 9 ms 8300 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8300 KB Output is correct
15 Correct 8 ms 8300 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8940 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 10 ms 8940 KB Output is correct
20 Correct 9 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 9 ms 8172 KB Output is correct
12 Correct 9 ms 8300 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8300 KB Output is correct
15 Correct 8 ms 8300 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8940 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 10 ms 8940 KB Output is correct
20 Correct 9 ms 8172 KB Output is correct
21 Correct 10 ms 8300 KB Output is correct
22 Correct 13 ms 11500 KB Output is correct
23 Correct 10 ms 8300 KB Output is correct
24 Correct 12 ms 11372 KB Output is correct
25 Correct 10 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 12536 KB Output is correct
2 Correct 594 ms 19660 KB Output is correct
3 Correct 555 ms 12428 KB Output is correct
4 Correct 541 ms 19500 KB Output is correct
5 Correct 540 ms 12560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 563 ms 14216 KB Output is correct
2 Correct 520 ms 14348 KB Output is correct
3 Correct 506 ms 14236 KB Output is correct
4 Correct 540 ms 14316 KB Output is correct
5 Correct 513 ms 14236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 21240 KB Output is correct
2 Correct 536 ms 21540 KB Output is correct
3 Correct 556 ms 21280 KB Output is correct
4 Correct 563 ms 21292 KB Output is correct
5 Correct 534 ms 21512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 585 ms 12536 KB Output is correct
12 Correct 594 ms 19660 KB Output is correct
13 Correct 555 ms 12428 KB Output is correct
14 Correct 541 ms 19500 KB Output is correct
15 Correct 540 ms 12560 KB Output is correct
16 Correct 529 ms 12440 KB Output is correct
17 Correct 568 ms 19684 KB Output is correct
18 Correct 604 ms 19676 KB Output is correct
19 Correct 520 ms 12448 KB Output is correct
20 Correct 558 ms 19624 KB Output is correct
21 Correct 532 ms 12472 KB Output is correct
22 Correct 535 ms 19600 KB Output is correct
23 Correct 564 ms 12636 KB Output is correct
24 Correct 539 ms 19608 KB Output is correct
25 Correct 554 ms 12660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 9 ms 8172 KB Output is correct
12 Correct 9 ms 8300 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8300 KB Output is correct
15 Correct 8 ms 8300 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8940 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 10 ms 8940 KB Output is correct
20 Correct 9 ms 8172 KB Output is correct
21 Correct 10 ms 8300 KB Output is correct
22 Correct 13 ms 11500 KB Output is correct
23 Correct 10 ms 8300 KB Output is correct
24 Correct 12 ms 11372 KB Output is correct
25 Correct 10 ms 8300 KB Output is correct
26 Correct 585 ms 12536 KB Output is correct
27 Correct 594 ms 19660 KB Output is correct
28 Correct 555 ms 12428 KB Output is correct
29 Correct 541 ms 19500 KB Output is correct
30 Correct 540 ms 12560 KB Output is correct
31 Correct 563 ms 14216 KB Output is correct
32 Correct 520 ms 14348 KB Output is correct
33 Correct 506 ms 14236 KB Output is correct
34 Correct 540 ms 14316 KB Output is correct
35 Correct 513 ms 14236 KB Output is correct
36 Correct 538 ms 21240 KB Output is correct
37 Correct 536 ms 21540 KB Output is correct
38 Correct 556 ms 21280 KB Output is correct
39 Correct 563 ms 21292 KB Output is correct
40 Correct 534 ms 21512 KB Output is correct
41 Correct 529 ms 12440 KB Output is correct
42 Correct 568 ms 19684 KB Output is correct
43 Correct 604 ms 19676 KB Output is correct
44 Correct 520 ms 12448 KB Output is correct
45 Correct 558 ms 19624 KB Output is correct
46 Correct 532 ms 12472 KB Output is correct
47 Correct 535 ms 19600 KB Output is correct
48 Correct 564 ms 12636 KB Output is correct
49 Correct 539 ms 19608 KB Output is correct
50 Correct 554 ms 12660 KB Output is correct
51 Correct 577 ms 14072 KB Output is correct
52 Correct 591 ms 20996 KB Output is correct
53 Correct 597 ms 14184 KB Output is correct
54 Correct 592 ms 20996 KB Output is correct
55 Correct 606 ms 14244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8172 KB Output is correct
2 Correct 8 ms 8172 KB Output is correct
3 Correct 8 ms 8172 KB Output is correct
4 Correct 8 ms 8172 KB Output is correct
5 Correct 8 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 8 ms 8172 KB Output is correct
8 Correct 8 ms 8172 KB Output is correct
9 Correct 9 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 9 ms 8172 KB Output is correct
12 Correct 9 ms 8300 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8300 KB Output is correct
15 Correct 8 ms 8300 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8940 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 10 ms 8940 KB Output is correct
20 Correct 9 ms 8172 KB Output is correct
21 Correct 10 ms 8300 KB Output is correct
22 Correct 13 ms 11500 KB Output is correct
23 Correct 10 ms 8300 KB Output is correct
24 Correct 12 ms 11372 KB Output is correct
25 Correct 10 ms 8300 KB Output is correct
26 Correct 585 ms 12536 KB Output is correct
27 Correct 594 ms 19660 KB Output is correct
28 Correct 555 ms 12428 KB Output is correct
29 Correct 541 ms 19500 KB Output is correct
30 Correct 540 ms 12560 KB Output is correct
31 Correct 563 ms 14216 KB Output is correct
32 Correct 520 ms 14348 KB Output is correct
33 Correct 506 ms 14236 KB Output is correct
34 Correct 540 ms 14316 KB Output is correct
35 Correct 513 ms 14236 KB Output is correct
36 Correct 538 ms 21240 KB Output is correct
37 Correct 536 ms 21540 KB Output is correct
38 Correct 556 ms 21280 KB Output is correct
39 Correct 563 ms 21292 KB Output is correct
40 Correct 534 ms 21512 KB Output is correct
41 Correct 529 ms 12440 KB Output is correct
42 Correct 568 ms 19684 KB Output is correct
43 Correct 604 ms 19676 KB Output is correct
44 Correct 520 ms 12448 KB Output is correct
45 Correct 558 ms 19624 KB Output is correct
46 Correct 532 ms 12472 KB Output is correct
47 Correct 535 ms 19600 KB Output is correct
48 Correct 564 ms 12636 KB Output is correct
49 Correct 539 ms 19608 KB Output is correct
50 Correct 554 ms 12660 KB Output is correct
51 Correct 577 ms 14072 KB Output is correct
52 Correct 591 ms 20996 KB Output is correct
53 Correct 597 ms 14184 KB Output is correct
54 Correct 592 ms 20996 KB Output is correct
55 Correct 606 ms 14244 KB Output is correct
56 Execution timed out 1049 ms 54476 KB Time limit exceeded
57 Halted 0 ms 0 KB -