Submission #227341

# Submission time Handle Problem Language Result Execution time Memory
227341 2020-04-27T04:54:10 Z Autoratch Pilot (NOI19_pilot) C++14
100 / 100
609 ms 49272 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 1;

int n,m;
pair<int,int> a[N],q[N];
int lr[N];
bool s[N];
long long ans[N],now;

void add(int x)
{
    int ll = x,rr = x;
    long long l = 0,r = 0;
    if(ll>1 and s[ll-1]) l = ll-1-lr[ll-1]+1,ll = lr[ll-1];
    if(rr<n and s[rr+1]) r = lr[rr+1]-(rr+1)+1,rr = lr[rr+1];
    now+=(l+1LL)*(r+1LL);
    lr[ll] = rr,lr[rr] = ll;
    s[x] = true;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;
    for(int i = 1;i <= n;i++) cin >> a[i].first,a[i].second = i;
    for(int i = 1;i <= m;i++) cin >> q[i].first,q[i].second = i;
    sort(q+1,q+m+1),sort(a+1,a+n+1);
    int x = 1,y = 1;
    while(y<=m)
    {
        while(x<=n and a[x].first<=q[y].first) add(a[x].second),x++;
        ans[q[y].second] = now,y++;
    }
    for(int i = 1;i <= m;i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1664 KB Output is correct
2 Correct 25 ms 1664 KB Output is correct
3 Correct 24 ms 1656 KB Output is correct
4 Correct 24 ms 1536 KB Output is correct
5 Correct 24 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3960 KB Output is correct
2 Correct 46 ms 4088 KB Output is correct
3 Correct 46 ms 4088 KB Output is correct
4 Correct 48 ms 4088 KB Output is correct
5 Correct 47 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 3960 KB Output is correct
2 Correct 48 ms 3960 KB Output is correct
3 Correct 51 ms 4124 KB Output is correct
4 Correct 47 ms 4088 KB Output is correct
5 Correct 48 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 29 ms 1664 KB Output is correct
12 Correct 25 ms 1664 KB Output is correct
13 Correct 24 ms 1656 KB Output is correct
14 Correct 24 ms 1536 KB Output is correct
15 Correct 24 ms 1536 KB Output is correct
16 Correct 24 ms 1528 KB Output is correct
17 Correct 24 ms 1664 KB Output is correct
18 Correct 24 ms 1664 KB Output is correct
19 Correct 23 ms 1536 KB Output is correct
20 Correct 24 ms 1664 KB Output is correct
21 Correct 26 ms 1536 KB Output is correct
22 Correct 25 ms 1536 KB Output is correct
23 Correct 24 ms 1656 KB Output is correct
24 Correct 23 ms 1536 KB Output is correct
25 Correct 24 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 29 ms 1664 KB Output is correct
27 Correct 25 ms 1664 KB Output is correct
28 Correct 24 ms 1656 KB Output is correct
29 Correct 24 ms 1536 KB Output is correct
30 Correct 24 ms 1536 KB Output is correct
31 Correct 48 ms 3960 KB Output is correct
32 Correct 46 ms 4088 KB Output is correct
33 Correct 46 ms 4088 KB Output is correct
34 Correct 48 ms 4088 KB Output is correct
35 Correct 47 ms 4088 KB Output is correct
36 Correct 45 ms 3960 KB Output is correct
37 Correct 48 ms 3960 KB Output is correct
38 Correct 51 ms 4124 KB Output is correct
39 Correct 47 ms 4088 KB Output is correct
40 Correct 48 ms 4220 KB Output is correct
41 Correct 24 ms 1528 KB Output is correct
42 Correct 24 ms 1664 KB Output is correct
43 Correct 24 ms 1664 KB Output is correct
44 Correct 23 ms 1536 KB Output is correct
45 Correct 24 ms 1664 KB Output is correct
46 Correct 26 ms 1536 KB Output is correct
47 Correct 25 ms 1536 KB Output is correct
48 Correct 24 ms 1656 KB Output is correct
49 Correct 23 ms 1536 KB Output is correct
50 Correct 24 ms 1536 KB Output is correct
51 Correct 54 ms 3964 KB Output is correct
52 Correct 54 ms 3704 KB Output is correct
53 Correct 56 ms 3960 KB Output is correct
54 Correct 54 ms 3704 KB Output is correct
55 Correct 57 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 29 ms 1664 KB Output is correct
27 Correct 25 ms 1664 KB Output is correct
28 Correct 24 ms 1656 KB Output is correct
29 Correct 24 ms 1536 KB Output is correct
30 Correct 24 ms 1536 KB Output is correct
31 Correct 48 ms 3960 KB Output is correct
32 Correct 46 ms 4088 KB Output is correct
33 Correct 46 ms 4088 KB Output is correct
34 Correct 48 ms 4088 KB Output is correct
35 Correct 47 ms 4088 KB Output is correct
36 Correct 45 ms 3960 KB Output is correct
37 Correct 48 ms 3960 KB Output is correct
38 Correct 51 ms 4124 KB Output is correct
39 Correct 47 ms 4088 KB Output is correct
40 Correct 48 ms 4220 KB Output is correct
41 Correct 24 ms 1528 KB Output is correct
42 Correct 24 ms 1664 KB Output is correct
43 Correct 24 ms 1664 KB Output is correct
44 Correct 23 ms 1536 KB Output is correct
45 Correct 24 ms 1664 KB Output is correct
46 Correct 26 ms 1536 KB Output is correct
47 Correct 25 ms 1536 KB Output is correct
48 Correct 24 ms 1656 KB Output is correct
49 Correct 23 ms 1536 KB Output is correct
50 Correct 24 ms 1536 KB Output is correct
51 Correct 54 ms 3964 KB Output is correct
52 Correct 54 ms 3704 KB Output is correct
53 Correct 56 ms 3960 KB Output is correct
54 Correct 54 ms 3704 KB Output is correct
55 Correct 57 ms 3960 KB Output is correct
56 Correct 592 ms 35528 KB Output is correct
57 Correct 591 ms 47696 KB Output is correct
58 Correct 558 ms 45560 KB Output is correct
59 Correct 553 ms 46328 KB Output is correct
60 Correct 609 ms 49272 KB Output is correct