답안 #320906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320906 2020-11-10T08:22:26 Z egas Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 184804 KB
#include <bits/stdc++.h>

using namespace std;

class SparseTable {

private:

    long long lookup[1000005][(long long)log2l(1000005)+1];

    void buildSparseTable(long long arr[], long long n) {

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

            lookup[i][0] = arr[i];

        for (long long j = 1; (1 << j) <= n; j++) {

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

                if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1])

                    lookup[i][j] = lookup[i][j - 1];

                else

                    lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1];

            }

        }

    }

public:

    SparseTable(vector<long long> &a) {

        long long num[a.size()];

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

            num[i]=a[i];

        }

        buildSparseTable(num,a.size());

    }

    long long query(long long L, long long R) {

        L--;

        R--;

        long long j = (long long)log2(R - L + 1);

        if (lookup[L][j] >= lookup[R - (1 << j) + 1][j])

            return lookup[L][j];

        else

            return lookup[R - (1 << j) + 1][j];

    }

};

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    long long m;

    cin >> m;

    vector<long long> a(n);

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

        cin >> a[i];

    }

    vector<long long> b(m);

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

        cin >> b[i];

    }

    vector<long long> diff(1000005,0);

    SparseTable ST(a);

    long long *last=new long long[1000005];

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

        last[a[i]]=-1;

    }

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

        long long ryt=0;

        long long l=i;

        long 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 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 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 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 long i=1; i<diff.size(); i++) {

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

    }

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

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

    }

    return 0;

}

Compilation message

pilot.cpp: In constructor 'SparseTable::SparseTable(std::vector<long long int>&)':
pilot.cpp:41:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(long long i = 0 ; i < a.size() ; i++) {
      |                               ~~^~~~~~~~~~
pilot.cpp: In function 'int32_t main()':
pilot.cpp:107:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for(long long i = 0 ; i < a.size() ; i++) {
      |                           ~~^~~~~~~~~~
pilot.cpp:199:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  199 |     for(long long i=1; i<diff.size(); i++) {
      |                        ~^~~~~~~~~~~~
pilot.cpp:205:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  205 |     for(long long i = 0 ; i < b.size() ; i++) {
      |                           ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 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 8172 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 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 8172 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 8300 KB Output is correct
19 Correct 8 ms 8940 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 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 8172 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 8300 KB Output is correct
19 Correct 8 ms 8940 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 9 ms 8428 KB Output is correct
22 Correct 11 ms 11500 KB Output is correct
23 Correct 9 ms 8428 KB Output is correct
24 Correct 11 ms 11500 KB Output is correct
25 Correct 8 ms 8428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 26084 KB Output is correct
2 Correct 197 ms 33508 KB Output is correct
3 Correct 163 ms 25704 KB Output is correct
4 Correct 176 ms 32228 KB Output is correct
5 Correct 157 ms 25316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 27232 KB Output is correct
2 Correct 166 ms 27364 KB Output is correct
3 Correct 164 ms 26980 KB Output is correct
4 Correct 173 ms 27876 KB Output is correct
5 Correct 164 ms 26852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 34660 KB Output is correct
2 Correct 174 ms 34280 KB Output is correct
3 Correct 169 ms 33892 KB Output is correct
4 Correct 183 ms 35428 KB Output is correct
5 Correct 174 ms 34532 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 166 ms 26084 KB Output is correct
12 Correct 197 ms 33508 KB Output is correct
13 Correct 163 ms 25704 KB Output is correct
14 Correct 176 ms 32228 KB Output is correct
15 Correct 157 ms 25316 KB Output is correct
16 Correct 174 ms 25316 KB Output is correct
17 Correct 190 ms 33380 KB Output is correct
18 Correct 193 ms 33636 KB Output is correct
19 Correct 159 ms 25196 KB Output is correct
20 Correct 187 ms 33124 KB Output is correct
21 Correct 177 ms 25316 KB Output is correct
22 Correct 188 ms 32612 KB Output is correct
23 Correct 174 ms 26596 KB Output is correct
24 Correct 178 ms 32356 KB Output is correct
25 Correct 165 ms 26084 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 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 8172 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 8300 KB Output is correct
19 Correct 8 ms 8940 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 9 ms 8428 KB Output is correct
22 Correct 11 ms 11500 KB Output is correct
23 Correct 9 ms 8428 KB Output is correct
24 Correct 11 ms 11500 KB Output is correct
25 Correct 8 ms 8428 KB Output is correct
26 Correct 166 ms 26084 KB Output is correct
27 Correct 197 ms 33508 KB Output is correct
28 Correct 163 ms 25704 KB Output is correct
29 Correct 176 ms 32228 KB Output is correct
30 Correct 157 ms 25316 KB Output is correct
31 Correct 167 ms 27232 KB Output is correct
32 Correct 166 ms 27364 KB Output is correct
33 Correct 164 ms 26980 KB Output is correct
34 Correct 173 ms 27876 KB Output is correct
35 Correct 164 ms 26852 KB Output is correct
36 Correct 172 ms 34660 KB Output is correct
37 Correct 174 ms 34280 KB Output is correct
38 Correct 169 ms 33892 KB Output is correct
39 Correct 183 ms 35428 KB Output is correct
40 Correct 174 ms 34532 KB Output is correct
41 Correct 174 ms 25316 KB Output is correct
42 Correct 190 ms 33380 KB Output is correct
43 Correct 193 ms 33636 KB Output is correct
44 Correct 159 ms 25196 KB Output is correct
45 Correct 187 ms 33124 KB Output is correct
46 Correct 177 ms 25316 KB Output is correct
47 Correct 188 ms 32612 KB Output is correct
48 Correct 174 ms 26596 KB Output is correct
49 Correct 178 ms 32356 KB Output is correct
50 Correct 165 ms 26084 KB Output is correct
51 Correct 191 ms 27492 KB Output is correct
52 Correct 218 ms 34404 KB Output is correct
53 Correct 195 ms 27876 KB Output is correct
54 Correct 211 ms 34288 KB Output is correct
55 Correct 197 ms 28004 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 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 8172 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 8300 KB Output is correct
19 Correct 8 ms 8940 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 9 ms 8428 KB Output is correct
22 Correct 11 ms 11500 KB Output is correct
23 Correct 9 ms 8428 KB Output is correct
24 Correct 11 ms 11500 KB Output is correct
25 Correct 8 ms 8428 KB Output is correct
26 Correct 166 ms 26084 KB Output is correct
27 Correct 197 ms 33508 KB Output is correct
28 Correct 163 ms 25704 KB Output is correct
29 Correct 176 ms 32228 KB Output is correct
30 Correct 157 ms 25316 KB Output is correct
31 Correct 167 ms 27232 KB Output is correct
32 Correct 166 ms 27364 KB Output is correct
33 Correct 164 ms 26980 KB Output is correct
34 Correct 173 ms 27876 KB Output is correct
35 Correct 164 ms 26852 KB Output is correct
36 Correct 172 ms 34660 KB Output is correct
37 Correct 174 ms 34280 KB Output is correct
38 Correct 169 ms 33892 KB Output is correct
39 Correct 183 ms 35428 KB Output is correct
40 Correct 174 ms 34532 KB Output is correct
41 Correct 174 ms 25316 KB Output is correct
42 Correct 190 ms 33380 KB Output is correct
43 Correct 193 ms 33636 KB Output is correct
44 Correct 159 ms 25196 KB Output is correct
45 Correct 187 ms 33124 KB Output is correct
46 Correct 177 ms 25316 KB Output is correct
47 Correct 188 ms 32612 KB Output is correct
48 Correct 174 ms 26596 KB Output is correct
49 Correct 178 ms 32356 KB Output is correct
50 Correct 165 ms 26084 KB Output is correct
51 Correct 191 ms 27492 KB Output is correct
52 Correct 218 ms 34404 KB Output is correct
53 Correct 195 ms 27876 KB Output is correct
54 Correct 211 ms 34288 KB Output is correct
55 Correct 197 ms 28004 KB Output is correct
56 Execution timed out 1109 ms 184804 KB Time limit exceeded
57 Halted 0 ms 0 KB -