Submission #143516

# Submission time Handle Problem Language Result Execution time Memory
143516 2019-08-14T12:57:42 Z kig9981 Employment (JOI16_employment) C++17
100 / 100
251 ms 10804 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];
vector<int> x;
vector<pair<int,int>> Q;

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 || i==N-1);
	v+=(i && A[i-1]<A[i]);
	v-=(i && A[i-1]>A[i]);
	v+=(i+1<N && A[i]>A[i+1]);
	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.push_back(A[i]);
	}
	Q.resize(M);
	for(auto &[a,b]: Q) {
		int t;
		cin>>t>>a; b=-1;
		if(t==2) {
			cin>>b; --a;
			x.push_back(b);
		}
	}
	sort(x.begin(),x.end());
	x.resize(unique(x.begin(),x.end())-x.begin());
	for(int i=0;i<N;i++) A[i]=lower_bound(x.begin(),x.end(),A[i])-x.begin();
	for(int i=0;i<N;i++) set_value(i,1);
	for(auto &[a,b]: Q) {
		if(b==-1) cout<<get_cnt(lower_bound(x.begin(),x.end(),a)-x.begin())/2<<'\n';
		else {
			set_value(a,-1);
			if(a) set_value(a-1,-1);
			if(a+1<N) set_value(a+1,-1);
			A[a]=lower_bound(x.begin(),x.end(),b)-x.begin();
			set_value(a,1);
			if(a) set_value(a-1,1);
			if(a+1<N) set_value(a+1,1);
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 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 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory 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 1144 KB Output is correct
5 Correct 29 ms 1912 KB Output is correct
6 Correct 43 ms 2712 KB Output is correct
7 Correct 68 ms 4024 KB Output is correct
8 Correct 86 ms 4876 KB Output is correct
9 Correct 147 ms 7640 KB Output is correct
10 Correct 142 ms 7144 KB Output is correct
11 Correct 169 ms 8756 KB Output is correct
12 Correct 198 ms 9840 KB Output is correct
13 Correct 203 ms 9740 KB Output is correct
14 Correct 189 ms 9568 KB Output is correct
15 Correct 190 ms 9712 KB Output is correct
16 Correct 196 ms 9844 KB Output is correct
17 Correct 194 ms 9840 KB Output is correct
18 Correct 197 ms 9968 KB Output is correct
19 Correct 198 ms 9836 KB Output is correct
20 Correct 195 ms 9868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 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 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 504 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 1144 KB Output is correct
20 Correct 29 ms 1912 KB Output is correct
21 Correct 43 ms 2712 KB Output is correct
22 Correct 68 ms 4024 KB Output is correct
23 Correct 86 ms 4876 KB Output is correct
24 Correct 147 ms 7640 KB Output is correct
25 Correct 142 ms 7144 KB Output is correct
26 Correct 169 ms 8756 KB Output is correct
27 Correct 198 ms 9840 KB Output is correct
28 Correct 203 ms 9740 KB Output is correct
29 Correct 189 ms 9568 KB Output is correct
30 Correct 190 ms 9712 KB Output is correct
31 Correct 196 ms 9844 KB Output is correct
32 Correct 194 ms 9840 KB Output is correct
33 Correct 197 ms 9968 KB Output is correct
34 Correct 198 ms 9836 KB Output is correct
35 Correct 195 ms 9868 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 17 ms 1144 KB Output is correct
40 Correct 30 ms 1912 KB Output is correct
41 Correct 52 ms 2904 KB Output is correct
42 Correct 75 ms 3956 KB Output is correct
43 Correct 102 ms 5104 KB Output is correct
44 Correct 191 ms 8816 KB Output is correct
45 Correct 154 ms 7280 KB Output is correct
46 Correct 173 ms 8076 KB Output is correct
47 Correct 239 ms 10488 KB Output is correct
48 Correct 238 ms 10804 KB Output is correct
49 Correct 234 ms 10444 KB Output is correct
50 Correct 228 ms 10424 KB Output is correct
51 Correct 237 ms 10644 KB Output is correct
52 Correct 251 ms 10708 KB Output is correct
53 Correct 236 ms 10728 KB Output is correct
54 Correct 240 ms 10732 KB Output is correct
55 Correct 244 ms 10732 KB Output is correct