답안 #344421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344421 2021-01-05T18:48:20 Z Nursik Pilot (NOI19_pilot) C++14
100 / 100
673 ms 36716 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end() 
#define ld long double

using namespace std; 
 
void data() {
	#ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
} 
void win()
{	
	ios_base::sync_with_stdio(0),
	cin.tie(0),cout.tie(0);
}

const ld eps = 1e-6; 

const int N = 1e6 + 500;
const int mod = 1e9 + 7;

const ll hh = 100010683;
const ll hh2 = 150005819;

int n, q;
int a[N], pref[N]; ll pref2[N];
void rec(int l = 1, int r = n)
{
	if (l == r)
	{
		pref2[a[l]]++;
		return;
	}
	int mid = (l + r) / 2;
	rec(l, mid);
	rec(mid + 1, r);
	for (int i = mid; i >= l; i--)
	{
		pref[i] = max(pref[i + 1], a[i]);
	} 
	int cur = 0, uk = mid + 1;
	for (int i = mid + 1; i <= r; i++)
	{
		cur = max(cur, a[i]);
		while (cur >= pref[uk - 1] && uk - 1 >= l)
		{
			uk--;
		}
		pref2[cur] += max(mid - uk + 1, 0);
	}
	for (int i = mid; i >= l; i--)
	{
		pref[i] = 0;
	}
	cur = 0;
	for (int i = mid + 1; i <= r; i++)
	{
		pref[i] = max(pref[i - 1], a[i]);
	}
	uk = mid;
	for (int i = mid; i >= l; i--)
	{
		cur = max(cur, a[i]);
		while (cur > pref[uk + 1] && uk + 1 <= r)
		{
			uk++;
		}
		pref2[cur] += max(uk - mid , 0);
	}
	for (int i = mid + 1; i <= r; i++)
	{
		pref[i] = 0;
	}
}   
int main()
{
	data();              
	win();
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	rec();
	pref2[0] = 0;
	for (int i = 1; i <= 1e6; i++)
	{
		pref2[i] += pref2[i - 1];
	}
	for (int i = 1; i <= q; i++)
	{
		int x;
		cin >> x;
		cout << pref2[x] << '\n';
	}
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 6 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 6 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 6 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 6 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 6 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 6 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 8940 KB Output is correct
2 Correct 37 ms 9580 KB Output is correct
3 Correct 32 ms 9452 KB Output is correct
4 Correct 34 ms 9452 KB Output is correct
5 Correct 31 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 9964 KB Output is correct
2 Correct 56 ms 11116 KB Output is correct
3 Correct 55 ms 10988 KB Output is correct
4 Correct 57 ms 11116 KB Output is correct
5 Correct 55 ms 10988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 9836 KB Output is correct
2 Correct 58 ms 11116 KB Output is correct
3 Correct 56 ms 11116 KB Output is correct
4 Correct 58 ms 11244 KB Output is correct
5 Correct 60 ms 11244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 34 ms 8940 KB Output is correct
12 Correct 37 ms 9580 KB Output is correct
13 Correct 32 ms 9452 KB Output is correct
14 Correct 34 ms 9452 KB Output is correct
15 Correct 31 ms 9452 KB Output is correct
16 Correct 31 ms 9452 KB Output is correct
17 Correct 39 ms 9580 KB Output is correct
18 Correct 37 ms 9580 KB Output is correct
19 Correct 31 ms 9452 KB Output is correct
20 Correct 40 ms 9580 KB Output is correct
21 Correct 30 ms 9452 KB Output is correct
22 Correct 34 ms 9580 KB Output is correct
23 Correct 33 ms 9580 KB Output is correct
24 Correct 34 ms 9580 KB Output is correct
25 Correct 32 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 6 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 6 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 6 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 34 ms 8940 KB Output is correct
27 Correct 37 ms 9580 KB Output is correct
28 Correct 32 ms 9452 KB Output is correct
29 Correct 34 ms 9452 KB Output is correct
30 Correct 31 ms 9452 KB Output is correct
31 Correct 56 ms 9964 KB Output is correct
32 Correct 56 ms 11116 KB Output is correct
33 Correct 55 ms 10988 KB Output is correct
34 Correct 57 ms 11116 KB Output is correct
35 Correct 55 ms 10988 KB Output is correct
36 Correct 56 ms 9836 KB Output is correct
37 Correct 58 ms 11116 KB Output is correct
38 Correct 56 ms 11116 KB Output is correct
39 Correct 58 ms 11244 KB Output is correct
40 Correct 60 ms 11244 KB Output is correct
41 Correct 31 ms 9452 KB Output is correct
42 Correct 39 ms 9580 KB Output is correct
43 Correct 37 ms 9580 KB Output is correct
44 Correct 31 ms 9452 KB Output is correct
45 Correct 40 ms 9580 KB Output is correct
46 Correct 30 ms 9452 KB Output is correct
47 Correct 34 ms 9580 KB Output is correct
48 Correct 33 ms 9580 KB Output is correct
49 Correct 34 ms 9580 KB Output is correct
50 Correct 32 ms 9452 KB Output is correct
51 Correct 59 ms 10988 KB Output is correct
52 Correct 64 ms 10860 KB Output is correct
53 Correct 58 ms 10988 KB Output is correct
54 Correct 66 ms 10860 KB Output is correct
55 Correct 59 ms 10988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Correct 6 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 8 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 6 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 6 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 6 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 6 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 34 ms 8940 KB Output is correct
27 Correct 37 ms 9580 KB Output is correct
28 Correct 32 ms 9452 KB Output is correct
29 Correct 34 ms 9452 KB Output is correct
30 Correct 31 ms 9452 KB Output is correct
31 Correct 56 ms 9964 KB Output is correct
32 Correct 56 ms 11116 KB Output is correct
33 Correct 55 ms 10988 KB Output is correct
34 Correct 57 ms 11116 KB Output is correct
35 Correct 55 ms 10988 KB Output is correct
36 Correct 56 ms 9836 KB Output is correct
37 Correct 58 ms 11116 KB Output is correct
38 Correct 56 ms 11116 KB Output is correct
39 Correct 58 ms 11244 KB Output is correct
40 Correct 60 ms 11244 KB Output is correct
41 Correct 31 ms 9452 KB Output is correct
42 Correct 39 ms 9580 KB Output is correct
43 Correct 37 ms 9580 KB Output is correct
44 Correct 31 ms 9452 KB Output is correct
45 Correct 40 ms 9580 KB Output is correct
46 Correct 30 ms 9452 KB Output is correct
47 Correct 34 ms 9580 KB Output is correct
48 Correct 33 ms 9580 KB Output is correct
49 Correct 34 ms 9580 KB Output is correct
50 Correct 32 ms 9452 KB Output is correct
51 Correct 59 ms 10988 KB Output is correct
52 Correct 64 ms 10860 KB Output is correct
53 Correct 58 ms 10988 KB Output is correct
54 Correct 66 ms 10860 KB Output is correct
55 Correct 59 ms 10988 KB Output is correct
56 Correct 673 ms 36204 KB Output is correct
57 Correct 627 ms 35948 KB Output is correct
58 Correct 588 ms 34412 KB Output is correct
59 Correct 604 ms 35048 KB Output is correct
60 Correct 654 ms 36716 KB Output is correct