답안 #742917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742917 2023-05-17T06:06:48 Z flappybird Employment (JOI16_employment) C++17
100 / 100
206 ms 13136 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int A[MAX];
int T[MAX];
int B[MAX];
int C[MAX];
int D[MAX];
struct fenwick {
	int N;
	vector<int> tree;
	fenwick(int N = 0) :N(N) { tree.resize(N + 1); }
	void upd(int i, int x) {
		i = N - i + 1;
		while (i <= N) {
			tree[i] += x;
			i += i & -i;
		}
	}
	int sum(int i) {
		int ans = 0;
		i = N + 1 - i;
		while (i) {
			ans += tree[i];
			i -= i & -i;
		}
		return ans;
	}
};
fenwick fen;
int cnt[MAX];
void refresh(int x) {
	int l, r;
	l = A[x - 1] < A[x];
	r = A[x] >= A[x + 1];
	cnt[x] = 0;
	if (l && r) cnt[x] = 1;
	if (!l && !r) cnt[x] = -1;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	int i;
	vector<int> v;
	for (i = 1; i <= N; i++) cin >> A[i], v.push_back(A[i]);
	for (i = 1; i <= Q; i++) {
		cin >> T[i];
		if (T[i] == 1) cin >> B[i];
		else cin >> C[i] >> D[i], v.push_back(D[i]);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (i = 1; i <= N; i++) A[i] = lower_bound(v.begin(), v.end(), A[i]) - v.begin() + 1;
	for (i = 1; i <= Q; i++) if (T[i] == 2) D[i] = lower_bound(v.begin(), v.end(), D[i]) - v.begin() + 1;
	int K = v.size();
	fen = fenwick(K);
	for (i = 1; i <= N; i++) refresh(i), fen.upd(A[i], cnt[i]);
	for (i = 1; i <= Q; i++) {
		if (T[i] == 1) {
			int ind = lower_bound(v.begin(), v.end(), B[i]) - v.begin() + 1;
			if (ind > K) cout << 0 << ln;
			else cout << fen.sum(ind) << ln;
		}
		else {
			for (int x = C[i] - 1; x <= C[i] + 1; x++) fen.upd(A[x], -cnt[x]);
			A[C[i]] = D[i];
			for (int x = C[i] - 1; x <= C[i] + 1; x++) {
				refresh(x);
				fen.upd(A[x], cnt[x]);
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 10 ms 1108 KB Output is correct
5 Correct 21 ms 1992 KB Output is correct
6 Correct 31 ms 2768 KB Output is correct
7 Correct 50 ms 4240 KB Output is correct
8 Correct 63 ms 5172 KB Output is correct
9 Correct 103 ms 8188 KB Output is correct
10 Correct 109 ms 7852 KB Output is correct
11 Correct 124 ms 9344 KB Output is correct
12 Correct 145 ms 10416 KB Output is correct
13 Correct 144 ms 10456 KB Output is correct
14 Correct 137 ms 10192 KB Output is correct
15 Correct 135 ms 10260 KB Output is correct
16 Correct 141 ms 10564 KB Output is correct
17 Correct 142 ms 10588 KB Output is correct
18 Correct 147 ms 10604 KB Output is correct
19 Correct 142 ms 10540 KB Output is correct
20 Correct 142 ms 10612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 476 KB Output is correct
19 Correct 10 ms 1108 KB Output is correct
20 Correct 21 ms 1992 KB Output is correct
21 Correct 31 ms 2768 KB Output is correct
22 Correct 50 ms 4240 KB Output is correct
23 Correct 63 ms 5172 KB Output is correct
24 Correct 103 ms 8188 KB Output is correct
25 Correct 109 ms 7852 KB Output is correct
26 Correct 124 ms 9344 KB Output is correct
27 Correct 145 ms 10416 KB Output is correct
28 Correct 144 ms 10456 KB Output is correct
29 Correct 137 ms 10192 KB Output is correct
30 Correct 135 ms 10260 KB Output is correct
31 Correct 141 ms 10564 KB Output is correct
32 Correct 142 ms 10588 KB Output is correct
33 Correct 147 ms 10604 KB Output is correct
34 Correct 142 ms 10540 KB Output is correct
35 Correct 142 ms 10612 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 544 KB Output is correct
39 Correct 13 ms 1272 KB Output is correct
40 Correct 26 ms 2256 KB Output is correct
41 Correct 43 ms 3464 KB Output is correct
42 Correct 62 ms 4756 KB Output is correct
43 Correct 78 ms 6084 KB Output is correct
44 Correct 148 ms 10736 KB Output is correct
45 Correct 143 ms 8788 KB Output is correct
46 Correct 140 ms 9764 KB Output is correct
47 Correct 183 ms 12540 KB Output is correct
48 Correct 175 ms 12808 KB Output is correct
49 Correct 172 ms 12788 KB Output is correct
50 Correct 177 ms 12616 KB Output is correct
51 Correct 178 ms 12896 KB Output is correct
52 Correct 189 ms 12936 KB Output is correct
53 Correct 206 ms 12948 KB Output is correct
54 Correct 198 ms 12996 KB Output is correct
55 Correct 202 ms 13136 KB Output is correct