답안 #491516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491516 2021-12-02T19:08:56 Z kingfran1907 Employment (JOI16_employment) C++14
100 / 100
184 ms 7108 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 1e6+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, q;
int niz[maxn];
int loga[maxn];
vector< int > v;
pair< int, int > qs[maxn];

void update(int x, int val) {
	for (x++; x < maxn; x += x & -x)
		loga[x] += val;
}

int query(int x) {
	int out = 0;
	for (x++; x > 0; x -= x & -x)
		out += loga[x];
	return out;
}

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%d", niz+i);
	
	for (int i = 0; i <= n; i++)
		v.push_back(niz[i]);
	for (int i = 0; i < q; i++) {
		int type;
		scanf("%d", &type);
		if (type == 1) {
			int x;
			scanf("%d", &x);
			qs[i] = make_pair(-1, x);
		} else {
			int x, y;
			scanf("%d%d", &x, &y);

			qs[i] = make_pair(x, y);
			//v.push_back(y);
		}
		v.push_back(qs[i].Y);
	}

	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	for (int i = 0; i <= n; i++)
		niz[i] = lower_bound(v.begin(), v.end(), niz[i]) - v.begin();
	for (int i = 0; i < q; i++) {
		qs[i].Y = lower_bound(v.begin(), v.end(), qs[i].Y) - v.begin();
	}

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

	//printf("Debug: ");
	//for (int i = 0; i <= n; i++)
	//	printf("%d ", niz[i]);
	//printf("\n");
	for (int i = 0; i < q; i++) {
		if (qs[i].X == -1) {
			printf("%d\n", query(qs[i].Y));
		} else {
			int x = qs[i].X;
			if (niz[x - 1] < niz[x]) {
				update(niz[x - 1] + 1, -1);
				update(niz[x] + 1, 1);
			}
			if (niz[x] < niz[x + 1]) {
				update(niz[x] + 1, -1);
				update(niz[x + 1] + 1, 1);
			}
			niz[x] = qs[i].Y;

			if (niz[x - 1] < niz[x]) {
				update(niz[x - 1] + 1, 1);
				update(niz[x] + 1, -1);
			}
			if (niz[x] < niz[x + 1]) {
				update(niz[x] + 1, 1);
				update(niz[x + 1] + 1, -1);
			}
		}
	}
	return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d", niz+i);
      |   ~~~~~^~~~~~~~~~~~~
employment.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d", &type);
      |   ~~~~~^~~~~~~~~~~~~
employment.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
employment.cpp:50:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |    scanf("%d%d", &x, &y);
      |    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 12 ms 924 KB Output is correct
5 Correct 23 ms 1452 KB Output is correct
6 Correct 39 ms 1976 KB Output is correct
7 Correct 58 ms 2856 KB Output is correct
8 Correct 84 ms 3552 KB Output is correct
9 Correct 132 ms 5740 KB Output is correct
10 Correct 113 ms 4840 KB Output is correct
11 Correct 155 ms 6356 KB Output is correct
12 Correct 173 ms 6972 KB Output is correct
13 Correct 168 ms 6936 KB Output is correct
14 Correct 171 ms 6996 KB Output is correct
15 Correct 162 ms 6804 KB Output is correct
16 Correct 166 ms 7040 KB Output is correct
17 Correct 175 ms 7108 KB Output is correct
18 Correct 180 ms 7036 KB Output is correct
19 Correct 167 ms 7040 KB Output is correct
20 Correct 172 ms 7088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 12 ms 924 KB Output is correct
20 Correct 23 ms 1452 KB Output is correct
21 Correct 39 ms 1976 KB Output is correct
22 Correct 58 ms 2856 KB Output is correct
23 Correct 84 ms 3552 KB Output is correct
24 Correct 132 ms 5740 KB Output is correct
25 Correct 113 ms 4840 KB Output is correct
26 Correct 155 ms 6356 KB Output is correct
27 Correct 173 ms 6972 KB Output is correct
28 Correct 168 ms 6936 KB Output is correct
29 Correct 171 ms 6996 KB Output is correct
30 Correct 162 ms 6804 KB Output is correct
31 Correct 166 ms 7040 KB Output is correct
32 Correct 175 ms 7108 KB Output is correct
33 Correct 180 ms 7036 KB Output is correct
34 Correct 167 ms 7040 KB Output is correct
35 Correct 172 ms 7088 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 12 ms 844 KB Output is correct
40 Correct 25 ms 1308 KB Output is correct
41 Correct 40 ms 1908 KB Output is correct
42 Correct 60 ms 2488 KB Output is correct
43 Correct 78 ms 3128 KB Output is correct
44 Correct 151 ms 5332 KB Output is correct
45 Correct 122 ms 4464 KB Output is correct
46 Correct 135 ms 4880 KB Output is correct
47 Correct 173 ms 6212 KB Output is correct
48 Correct 176 ms 6456 KB Output is correct
49 Correct 174 ms 6324 KB Output is correct
50 Correct 170 ms 6272 KB Output is correct
51 Correct 184 ms 6596 KB Output is correct
52 Correct 178 ms 6436 KB Output is correct
53 Correct 180 ms 6448 KB Output is correct
54 Correct 182 ms 6492 KB Output is correct
55 Correct 178 ms 6444 KB Output is correct