답안 #143526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143526 2019-08-14T13:25:06 Z kig9981 Employment (JOI16_employment) C++17
100 / 100
234 ms 5636 KB
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int N, tree[400001], A[200000], x[400000], sz;
pair<int,int> Q[200000];

void update(int n, int v)
{
	for(++n;n;n-=n&-n) tree[n]+=v;
}

int get_cnt(int n)
{
	int ret=0;
	for(++n;n<=400000;n+=n&-n) ret+=tree[n];
	return ret;
}

void set_value(int i, int m)
{
	int v=i==0;
	v+=(i && A[i-1]<A[i]);
	v-=(i+1<N && A[i]<A[i+1]);
	update(A[i],m*v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int M;
	cin>>N>>M;
	for(int i=0;i<N;i++) {
		cin>>A[i];
		x[sz++]=A[i];
	}
	for(int i=0;i<M;i++) {
		int t;
		cin>>t>>Q[i].first; Q[i].second=-1;
		if(t==2) {
			cin>>Q[i].second; --Q[i].first;
			x[sz++]=Q[i].second;
		}
	}
	sort(x,x+sz);
	sz=unique(x,x+sz)-x;
	for(int i=0;i<N;i++) A[i]=lower_bound(x,x+sz,A[i])-x;
	for(int i=0;i<N;i++) set_value(i,1);
	for(int i=0;i<M;i++) {
		if(Q[i].second==-1) cout<<get_cnt(lower_bound(x,x+sz,Q[i].first)-x)<<'\n';
		else {
			set_value(Q[i].first,-1);
			if(Q[i].first) set_value(Q[i].first-1,-1);
			if(Q[i].first+1<N) set_value(Q[i].first+1,-1);
			A[Q[i].first]=lower_bound(x,x+sz,Q[i].second)-x;
			set_value(Q[i].first,1);
			if(Q[i].first) set_value(Q[i].first-1,1);
			if(Q[i].first+1<N) set_value(Q[i].first+1,1);
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 4 ms 476 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 15 ms 760 KB Output is correct
5 Correct 27 ms 1144 KB Output is correct
6 Correct 41 ms 1528 KB Output is correct
7 Correct 66 ms 2168 KB Output is correct
8 Correct 82 ms 2680 KB Output is correct
9 Correct 139 ms 4216 KB Output is correct
10 Correct 133 ms 4088 KB Output is correct
11 Correct 167 ms 4860 KB Output is correct
12 Correct 187 ms 5340 KB Output is correct
13 Correct 186 ms 5368 KB Output is correct
14 Correct 182 ms 5416 KB Output is correct
15 Correct 181 ms 5320 KB Output is correct
16 Correct 188 ms 5368 KB Output is correct
17 Correct 191 ms 5496 KB Output is correct
18 Correct 187 ms 5468 KB Output is correct
19 Correct 192 ms 5516 KB Output is correct
20 Correct 186 ms 5368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 3 ms 380 KB Output is correct
17 Correct 4 ms 476 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 15 ms 760 KB Output is correct
20 Correct 27 ms 1144 KB Output is correct
21 Correct 41 ms 1528 KB Output is correct
22 Correct 66 ms 2168 KB Output is correct
23 Correct 82 ms 2680 KB Output is correct
24 Correct 139 ms 4216 KB Output is correct
25 Correct 133 ms 4088 KB Output is correct
26 Correct 167 ms 4860 KB Output is correct
27 Correct 187 ms 5340 KB Output is correct
28 Correct 186 ms 5368 KB Output is correct
29 Correct 182 ms 5416 KB Output is correct
30 Correct 181 ms 5320 KB Output is correct
31 Correct 188 ms 5368 KB Output is correct
32 Correct 191 ms 5496 KB Output is correct
33 Correct 187 ms 5468 KB Output is correct
34 Correct 192 ms 5516 KB Output is correct
35 Correct 186 ms 5368 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 4 ms 380 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 17 ms 632 KB Output is correct
40 Correct 31 ms 1144 KB Output is correct
41 Correct 51 ms 1656 KB Output is correct
42 Correct 74 ms 2168 KB Output is correct
43 Correct 99 ms 2680 KB Output is correct
44 Correct 200 ms 4696 KB Output is correct
45 Correct 152 ms 4016 KB Output is correct
46 Correct 173 ms 4492 KB Output is correct
47 Correct 224 ms 5612 KB Output is correct
48 Correct 228 ms 5496 KB Output is correct
49 Correct 229 ms 5496 KB Output is correct
50 Correct 221 ms 5496 KB Output is correct
51 Correct 233 ms 5636 KB Output is correct
52 Correct 231 ms 5624 KB Output is correct
53 Correct 228 ms 5628 KB Output is correct
54 Correct 234 ms 5612 KB Output is correct
55 Correct 230 ms 5612 KB Output is correct