답안 #391801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391801 2021-04-19T23:31:08 Z maomao90 Pilot (NOI19_pilot) C++14
100 / 100
618 ms 28860 KB
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define FI first
#define SE second
typedef pair <int, int> ii;
typedef long long ll;
#define INF 1000000005

int n, q;
stack<ii> stk;

ll fw[1000005];
void update(int i, ll v) {
	for (; i < 1000005; i += (i & -i)) fw[i] += v;
}
void update(int s, int e, ll v) {
	if (e < s) return;
	update(s, v);
	update(e + 1, -v);
}
ll query(int i) {
	ll res = 0;
	for (; i > 0; i -= (i & -i)) res += fw[i];
	return res;
}

int main() {
	scanf("%d%d", &n, &q);
	stk.emplace(INF, -1);
	for (int i = 0; i <= n; i++) {
		int h; 
		if (i == n) h = INF - 1;
		else scanf("%d", &h);
		while (stk.size() > 1 && h > stk.top().FI) {
			int tp, tpi; tie(tp, tpi) = stk.top(); stk.pop();
			int prv, prvi; tie(prv, prvi) = stk.top();
			ll d = i - prvi - 1;
			update(tp, min(prv, h) - 1, d * (d + 1) / 2);
		}
		stk.emplace(h, i);
	}
	for (int i = 0; i < q; i++) {
		int y; scanf("%d", &y);
		printf("%lld\n", query(y));
	}
	return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:35:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |   else scanf("%d", &h);
      |        ~~~~~^~~~~~~~~~
pilot.cpp:45:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   int y; scanf("%d", &y);
      |          ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 716 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 684 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 716 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 684 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 2220 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 716 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 684 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 2220 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 5708 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1588 KB Output is correct
2 Correct 29 ms 8752 KB Output is correct
3 Correct 21 ms 1556 KB Output is correct
4 Correct 32 ms 8596 KB Output is correct
5 Correct 20 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 3052 KB Output is correct
2 Correct 48 ms 3168 KB Output is correct
3 Correct 48 ms 3144 KB Output is correct
4 Correct 48 ms 3092 KB Output is correct
5 Correct 49 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 10280 KB Output is correct
2 Correct 60 ms 10308 KB Output is correct
3 Correct 60 ms 10352 KB Output is correct
4 Correct 56 ms 10288 KB Output is correct
5 Correct 59 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 20 ms 1588 KB Output is correct
12 Correct 29 ms 8752 KB Output is correct
13 Correct 21 ms 1556 KB Output is correct
14 Correct 32 ms 8596 KB Output is correct
15 Correct 20 ms 1484 KB Output is correct
16 Correct 21 ms 1560 KB Output is correct
17 Correct 30 ms 8652 KB Output is correct
18 Correct 31 ms 8780 KB Output is correct
19 Correct 19 ms 1548 KB Output is correct
20 Correct 30 ms 8740 KB Output is correct
21 Correct 19 ms 1580 KB Output is correct
22 Correct 30 ms 8624 KB Output is correct
23 Correct 21 ms 1612 KB Output is correct
24 Correct 29 ms 8720 KB Output is correct
25 Correct 20 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 716 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 684 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 2220 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 5708 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 20 ms 1588 KB Output is correct
27 Correct 29 ms 8752 KB Output is correct
28 Correct 21 ms 1556 KB Output is correct
29 Correct 32 ms 8596 KB Output is correct
30 Correct 20 ms 1484 KB Output is correct
31 Correct 47 ms 3052 KB Output is correct
32 Correct 48 ms 3168 KB Output is correct
33 Correct 48 ms 3144 KB Output is correct
34 Correct 48 ms 3092 KB Output is correct
35 Correct 49 ms 3076 KB Output is correct
36 Correct 64 ms 10280 KB Output is correct
37 Correct 60 ms 10308 KB Output is correct
38 Correct 60 ms 10352 KB Output is correct
39 Correct 56 ms 10288 KB Output is correct
40 Correct 59 ms 10348 KB Output is correct
41 Correct 21 ms 1560 KB Output is correct
42 Correct 30 ms 8652 KB Output is correct
43 Correct 31 ms 8780 KB Output is correct
44 Correct 19 ms 1548 KB Output is correct
45 Correct 30 ms 8740 KB Output is correct
46 Correct 19 ms 1580 KB Output is correct
47 Correct 30 ms 8624 KB Output is correct
48 Correct 21 ms 1612 KB Output is correct
49 Correct 29 ms 8720 KB Output is correct
50 Correct 20 ms 1612 KB Output is correct
51 Correct 51 ms 2936 KB Output is correct
52 Correct 62 ms 9980 KB Output is correct
53 Correct 52 ms 3140 KB Output is correct
54 Correct 66 ms 10008 KB Output is correct
55 Correct 53 ms 3012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 716 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 684 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 2220 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 5708 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 20 ms 1588 KB Output is correct
27 Correct 29 ms 8752 KB Output is correct
28 Correct 21 ms 1556 KB Output is correct
29 Correct 32 ms 8596 KB Output is correct
30 Correct 20 ms 1484 KB Output is correct
31 Correct 47 ms 3052 KB Output is correct
32 Correct 48 ms 3168 KB Output is correct
33 Correct 48 ms 3144 KB Output is correct
34 Correct 48 ms 3092 KB Output is correct
35 Correct 49 ms 3076 KB Output is correct
36 Correct 64 ms 10280 KB Output is correct
37 Correct 60 ms 10308 KB Output is correct
38 Correct 60 ms 10352 KB Output is correct
39 Correct 56 ms 10288 KB Output is correct
40 Correct 59 ms 10348 KB Output is correct
41 Correct 21 ms 1560 KB Output is correct
42 Correct 30 ms 8652 KB Output is correct
43 Correct 31 ms 8780 KB Output is correct
44 Correct 19 ms 1548 KB Output is correct
45 Correct 30 ms 8740 KB Output is correct
46 Correct 19 ms 1580 KB Output is correct
47 Correct 30 ms 8624 KB Output is correct
48 Correct 21 ms 1612 KB Output is correct
49 Correct 29 ms 8720 KB Output is correct
50 Correct 20 ms 1612 KB Output is correct
51 Correct 51 ms 2936 KB Output is correct
52 Correct 62 ms 9980 KB Output is correct
53 Correct 52 ms 3140 KB Output is correct
54 Correct 66 ms 10008 KB Output is correct
55 Correct 53 ms 3012 KB Output is correct
56 Correct 618 ms 28212 KB Output is correct
57 Correct 598 ms 28064 KB Output is correct
58 Correct 544 ms 26560 KB Output is correct
59 Correct 575 ms 27604 KB Output is correct
60 Correct 615 ms 28860 KB Output is correct