답안 #399792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399792 2021-05-06T15:41:16 Z Fidisk Pilot (NOI19_pilot) C++14
100 / 100
876 ms 75408 KB
#include <bits/stdc++.h>
using namespace std;

#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;

const ll base=361;
const ll mod=1e9+7;
const ld eps=1e-5;
const ll maxn=1e6;

ll n,m,i,a[5000009],k,b[5000009],r[5000009],l[5000009],j,ans,pre[5000009];
vector<pll> g;
vector<ll> q;

int main(){
    IO;
    cin>>n>>m;
    for (i=1;i<=n;i++) {
        cin>>a[i];
    }
    for (i=1;i<=n;i++) {
        while (!q.empty()&&a[q.back()]<=a[i]) {
            r[q.back()]=i-1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        r[q.back()]=n;
        q.pop_back();
    }
    for (i=1;i<=n;i++) {
        while (!q.empty()&&a[q.back()]<=a[i]) {
            r[q.back()]=i-1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        r[q.back()]=n;
        q.pop_back();
    }
    for (i=n;i>=1;i--) {
        while (!q.empty()&&a[q.back()]<a[i]) {
            l[q.back()]=i+1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        l[q.back()]=1;
        q.pop_back();
    }
    for (i=1;i<=n;i++) {
        g.push_back({a[i],(i-l[i]+1)*(r[i]-i+1)});
    }
    sort(g.begin(),g.end());
    for (i=1;i<=n;i++) {
        b[i]=g[i-1].fi;
        pre[i]=pre[i-1]+g[i-1].se;
    }
    for (i=1;i<=m;i++) {
        cin>>k;
        ans=0;
        for (j=n;j>0;j/=2) {
            while (ans+j<=n&&k>=b[ans+j]) {
                ans+=j;
            }
        }
        cout<<pre[ans]<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5728 KB Output is correct
2 Correct 26 ms 5820 KB Output is correct
3 Correct 25 ms 5500 KB Output is correct
4 Correct 25 ms 5420 KB Output is correct
5 Correct 25 ms 5528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 7296 KB Output is correct
2 Correct 47 ms 7228 KB Output is correct
3 Correct 47 ms 7080 KB Output is correct
4 Correct 50 ms 7472 KB Output is correct
5 Correct 46 ms 7100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 7356 KB Output is correct
2 Correct 53 ms 7228 KB Output is correct
3 Correct 54 ms 7232 KB Output is correct
4 Correct 55 ms 7664 KB Output is correct
5 Correct 55 ms 7344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 26 ms 5728 KB Output is correct
12 Correct 26 ms 5820 KB Output is correct
13 Correct 25 ms 5500 KB Output is correct
14 Correct 25 ms 5420 KB Output is correct
15 Correct 25 ms 5528 KB Output is correct
16 Correct 25 ms 5508 KB Output is correct
17 Correct 26 ms 5868 KB Output is correct
18 Correct 27 ms 5912 KB Output is correct
19 Correct 25 ms 5436 KB Output is correct
20 Correct 27 ms 5764 KB Output is correct
21 Correct 25 ms 5460 KB Output is correct
22 Correct 25 ms 5436 KB Output is correct
23 Correct 27 ms 5900 KB Output is correct
24 Correct 24 ms 5476 KB Output is correct
25 Correct 26 ms 5668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 26 ms 5728 KB Output is correct
27 Correct 26 ms 5820 KB Output is correct
28 Correct 25 ms 5500 KB Output is correct
29 Correct 25 ms 5420 KB Output is correct
30 Correct 25 ms 5528 KB Output is correct
31 Correct 46 ms 7296 KB Output is correct
32 Correct 47 ms 7228 KB Output is correct
33 Correct 47 ms 7080 KB Output is correct
34 Correct 50 ms 7472 KB Output is correct
35 Correct 46 ms 7100 KB Output is correct
36 Correct 52 ms 7356 KB Output is correct
37 Correct 53 ms 7228 KB Output is correct
38 Correct 54 ms 7232 KB Output is correct
39 Correct 55 ms 7664 KB Output is correct
40 Correct 55 ms 7344 KB Output is correct
41 Correct 25 ms 5508 KB Output is correct
42 Correct 26 ms 5868 KB Output is correct
43 Correct 27 ms 5912 KB Output is correct
44 Correct 25 ms 5436 KB Output is correct
45 Correct 27 ms 5764 KB Output is correct
46 Correct 25 ms 5460 KB Output is correct
47 Correct 25 ms 5436 KB Output is correct
48 Correct 27 ms 5900 KB Output is correct
49 Correct 24 ms 5476 KB Output is correct
50 Correct 26 ms 5668 KB Output is correct
51 Correct 56 ms 6540 KB Output is correct
52 Correct 62 ms 6340 KB Output is correct
53 Correct 56 ms 6628 KB Output is correct
54 Correct 61 ms 6244 KB Output is correct
55 Correct 56 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 26 ms 5728 KB Output is correct
27 Correct 26 ms 5820 KB Output is correct
28 Correct 25 ms 5500 KB Output is correct
29 Correct 25 ms 5420 KB Output is correct
30 Correct 25 ms 5528 KB Output is correct
31 Correct 46 ms 7296 KB Output is correct
32 Correct 47 ms 7228 KB Output is correct
33 Correct 47 ms 7080 KB Output is correct
34 Correct 50 ms 7472 KB Output is correct
35 Correct 46 ms 7100 KB Output is correct
36 Correct 52 ms 7356 KB Output is correct
37 Correct 53 ms 7228 KB Output is correct
38 Correct 54 ms 7232 KB Output is correct
39 Correct 55 ms 7664 KB Output is correct
40 Correct 55 ms 7344 KB Output is correct
41 Correct 25 ms 5508 KB Output is correct
42 Correct 26 ms 5868 KB Output is correct
43 Correct 27 ms 5912 KB Output is correct
44 Correct 25 ms 5436 KB Output is correct
45 Correct 27 ms 5764 KB Output is correct
46 Correct 25 ms 5460 KB Output is correct
47 Correct 25 ms 5436 KB Output is correct
48 Correct 27 ms 5900 KB Output is correct
49 Correct 24 ms 5476 KB Output is correct
50 Correct 26 ms 5668 KB Output is correct
51 Correct 56 ms 6540 KB Output is correct
52 Correct 62 ms 6340 KB Output is correct
53 Correct 56 ms 6628 KB Output is correct
54 Correct 61 ms 6244 KB Output is correct
55 Correct 56 ms 6620 KB Output is correct
56 Correct 856 ms 68824 KB Output is correct
57 Correct 841 ms 74576 KB Output is correct
58 Correct 779 ms 69136 KB Output is correct
59 Correct 789 ms 70980 KB Output is correct
60 Correct 876 ms 75408 KB Output is correct