Submission #257948

# Submission time Handle Problem Language Result Execution time Memory
257948 2020-08-05T05:53:02 Z 임성재(#5053) Employment (JOI16_employment) C++17
10 / 100
162 ms 5736 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, q;
int a[200010];
int t[200010];
int b[200010];
int c[200010];
int tree[201010];
vector<int> v;

void update(int i, int x) {
	//cout << i << "!!! " << x << endl;

	while(i <= 200010) {
		tree[i] += x;
		i += i & -i;
	}
}

int sum(int i) {
	int ret = 0;

	while(i) {
		ret += tree[i];

		i -= i & -i;
	}

	return ret;
}

bool up(int x) {
	if(x < 1 || x > n) return false;

	if(a[x-1] < a[x] && a[x] >= a[x+1]) return true;
	return false;
}

bool down(int x) {
	if(x < 1 || x > n) return false;
	if(a[x-1] >= a[x] && a[x] < a[x+1]) return true;
	return false;
}

int main() {
	fast;

	cin >> n >> q;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
		v.eb(a[i]);
	}

	for(int i=1; i<=q; i++) {
		cin >> t[i];

		if(t[i] == 2) cin >> b[i];

		cin >> c[i];

		v.eb(c[i]);
	}

	sort(all(v));
	v.erase(unique(all(v)), v.end());

	for(int i=1; i<=n; i++) {
		a[i] = lower_bound(all(v), a[i]) - v.begin() + 1;
	}

	for(int i=1; i<=n; i++) {
		if(up(i)) update(a[i]+1, -1);
		if(down(i)) update(a[i]+1, 1);
	}

	for(int i=1; i<=q; i++) {
		c[i] = lower_bound(all(v), c[i]) - v.begin() + 1;

		if(t[i] == 1) {
			cout << sum(c[i]) + 1 << "\n";
		}
		else {
			if(up(b[i])) update(a[b[i]]+1, 1);
			if(down(b[i])) update(a[b[i]]+1, -1);
			if(up(b[i]+1)) update(a[b[i]+1]+1, 1);
			if(down(b[i]+1)) update(a[b[i]+1]+1, -1);
			if(up(b[i]-1)) update(a[b[i]-1]+1, 1);
			if(down(b[i]-1)) update(a[b[i]-1]+1, -1);

			a[b[i]] = c[i];

			if(up(b[i])) update(a[b[i]]+1, -1);
			if(down(b[i])) update(a[b[i]]+1, 1);
			if(up(b[i]+1)) update(a[b[i]+1]+1, -1);
			if(down(b[i]+1)) update(a[b[i]+1]+1, 1);
			if(up(b[i]-1)) update(a[b[i]-1]+1, -1);
			if(down(b[i]-1)) update(a[b[i]-1]+1, 1);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 15 ms 1024 KB Output is correct
5 Correct 28 ms 1528 KB Output is correct
6 Correct 47 ms 2164 KB Output is correct
7 Correct 71 ms 2928 KB Output is correct
8 Correct 90 ms 3564 KB Output is correct
9 Incorrect 162 ms 5736 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 15 ms 1024 KB Output is correct
20 Correct 28 ms 1528 KB Output is correct
21 Correct 47 ms 2164 KB Output is correct
22 Correct 71 ms 2928 KB Output is correct
23 Correct 90 ms 3564 KB Output is correct
24 Incorrect 162 ms 5736 KB Output isn't correct
25 Halted 0 ms 0 KB -