답안 #157029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157029 2019-10-09T07:44:21 Z maruii Employment (JOI16_employment) C++14
100 / 100
267 ms 12904 KB
#include <bits/stdc++.h>
using namespace std;

const int SIZE = 1 << 19;
struct ST {
	int A[2 * SIZE];
	void update(int s, int e, int v) {
		for (s += SIZE, e += SIZE; s <= e; s >>= 1, e >>= 1) {
			if ( s & 1) A[s++] += v;
			if (~e & 1) A[e--] += v;
		}
	}
	int query(int x) {
		int ret = 0;
		for (x += SIZE; x; x >>= 1) ret += A[x];
		return ret;
	}
} seg;

struct In {
	int q, x, y;
} in[200005];

int A[200005];
vector<int> xx(1);

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, M; cin >> N >> M;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
		xx.push_back(A[i]);
	}
	for (int i = 0; i < M; ++i) {
		int q, x, y = 0; cin >> q >> x;
		if (q == 2) {
			cin >> y;
			xx.push_back(y);
		}
		in[i] = {q, x, y};
	}
	sort(xx.begin(), xx.end());
	xx.erase(unique(xx.begin(), xx.end()), xx.end());
	for (int i = 1; i <= N; ++i) A[i] = lower_bound(xx.begin(), xx.end(), A[i]) - xx.begin();
	for (int i = 0; i < M; ++i) {
		if (in[i].q == 1) in[i].x = lower_bound(xx.begin(), xx.end(), in[i].x) - xx.begin();
		else in[i].y = lower_bound(xx.begin(), xx.end(), in[i].y) - xx.begin();
	}
	for (int i = 0; i < N; ++i)
		if (A[i] < A[i + 1]) seg.update(A[i] + 1, A[i + 1], 1);
	for (int i = 0; i < M; ++i) {
		int q, x, y;
		q = in[i].q, x = in[i].x, y = in[i].y;
		if (q == 1) {
			printf("%d\n", seg.query(x));
		}
		else {
			if (A[x] < A[x + 1]) seg.update(A[x] + 1, A[x + 1], -1);
			if (A[x - 1] < A[x]) seg.update(A[x - 1] + 1, A[x], -1);
			if (y < A[x + 1]) seg.update(y + 1, A[x + 1], 1);
			if (A[x - 1] < y) seg.update(A[x - 1] + 1, y, 1);
			A[x] = y;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 16 ms 1400 KB Output is correct
5 Correct 30 ms 2168 KB Output is correct
6 Correct 45 ms 3064 KB Output is correct
7 Correct 73 ms 4596 KB Output is correct
8 Correct 92 ms 5592 KB Output is correct
9 Correct 148 ms 8880 KB Output is correct
10 Correct 146 ms 8300 KB Output is correct
11 Correct 178 ms 10184 KB Output is correct
12 Correct 199 ms 11376 KB Output is correct
13 Correct 200 ms 11376 KB Output is correct
14 Correct 196 ms 11124 KB Output is correct
15 Correct 200 ms 11248 KB Output is correct
16 Correct 215 ms 11504 KB Output is correct
17 Correct 209 ms 11504 KB Output is correct
18 Correct 209 ms 11396 KB Output is correct
19 Correct 203 ms 11372 KB Output is correct
20 Correct 202 ms 11540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 4 ms 504 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 16 ms 1400 KB Output is correct
20 Correct 30 ms 2168 KB Output is correct
21 Correct 45 ms 3064 KB Output is correct
22 Correct 73 ms 4596 KB Output is correct
23 Correct 92 ms 5592 KB Output is correct
24 Correct 148 ms 8880 KB Output is correct
25 Correct 146 ms 8300 KB Output is correct
26 Correct 178 ms 10184 KB Output is correct
27 Correct 199 ms 11376 KB Output is correct
28 Correct 200 ms 11376 KB Output is correct
29 Correct 196 ms 11124 KB Output is correct
30 Correct 200 ms 11248 KB Output is correct
31 Correct 215 ms 11504 KB Output is correct
32 Correct 209 ms 11504 KB Output is correct
33 Correct 209 ms 11396 KB Output is correct
34 Correct 203 ms 11372 KB Output is correct
35 Correct 202 ms 11540 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 504 KB Output is correct
39 Correct 19 ms 1528 KB Output is correct
40 Correct 33 ms 2168 KB Output is correct
41 Correct 57 ms 3448 KB Output is correct
42 Correct 82 ms 4596 KB Output is correct
43 Correct 112 ms 6000 KB Output is correct
44 Correct 211 ms 10480 KB Output is correct
45 Correct 170 ms 8684 KB Output is correct
46 Correct 189 ms 9584 KB Output is correct
47 Correct 252 ms 12236 KB Output is correct
48 Correct 267 ms 12560 KB Output is correct
49 Correct 256 ms 12520 KB Output is correct
50 Correct 257 ms 12344 KB Output is correct
51 Correct 265 ms 12760 KB Output is correct
52 Correct 263 ms 12700 KB Output is correct
53 Correct 261 ms 12780 KB Output is correct
54 Correct 263 ms 12724 KB Output is correct
55 Correct 263 ms 12904 KB Output is correct