Submission #53852

# Submission time Handle Problem Language Result Execution time Memory
53852 2018-07-01T09:48:15 Z ainta Employment (JOI16_employment) C++17
100 / 100
355 ms 6904 KB
#include<cstdio>
#include<algorithm>
#define SZ 401000
using namespace std;
int n, m;
int w[SZ];
int X[SZ], BIT[SZ], CX;
struct Query {
	int a, b, c;
}Q[SZ];
void Add(int a, int b) {
	while (a <= CX + 1) {
		BIT[a] += b;
		a += (a&-a);
	}
}
int Sum(int a) {
	int r = 0;
	while (a) {
		r += BIT[a];
		a -= (a&-a);
	}
	return r;
}
void Go(int a, int b) {
	if (a <= n && w[a - 1] <= w[a]) {
		Add(w[a - 1] + 1, b);
		Add(w[a] + 1, -b);
	}
}
int main() {
	int i, a, b, c;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		X[++CX] = w[i];
	}
	for (i = 1; i <= m; i++) {
		scanf("%d%d", &Q[i].c, &Q[i].a);
		Q[i].b = 0;
		if (Q[i].c == 2) {
			scanf("%d", &Q[i].b);
			X[++CX] = Q[i].b;
		}
	}
	sort(X + 1, X + CX + 1);
	for (i = 1; i <= n; i++) {
		w[i] = lower_bound(X + 1, X + CX + 1, w[i]) - X;
		Go(i, 1);
	}
	for (i = 1; i <= m; i++) {
		a = Q[i].a, b = Q[i].b, c = Q[i].c;
		if (c == 1) {
			a = lower_bound(X + 1, X + CX + 1, a) - X;
			printf("%d\n", Sum(a));
		}
		else {
			b = lower_bound(X + 1, X + CX + 1, b) - X;
			Go(a, -1);
			Go(a + 1, -1);
			w[a] = b;
			Go(a, 1);
			Go(a + 1, 1);
		}
	}
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &w[i]);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &Q[i].c, &Q[i].a);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
employment.cpp:42:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &Q[i].b);
    ~~~~~^~~~~~~~~~~~~~~
# 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 2 ms 412 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 ms 752 KB Output is correct
10 Correct 5 ms 752 KB Output is correct
11 Correct 4 ms 752 KB Output is correct
12 Correct 5 ms 780 KB Output is correct
13 Correct 5 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 6 ms 780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 780 KB Output is correct
2 Correct 4 ms 780 KB Output is correct
3 Correct 4 ms 780 KB Output is correct
4 Correct 15 ms 1084 KB Output is correct
5 Correct 30 ms 1596 KB Output is correct
6 Correct 47 ms 2120 KB Output is correct
7 Correct 73 ms 2772 KB Output is correct
8 Correct 90 ms 3412 KB Output is correct
9 Correct 152 ms 5332 KB Output is correct
10 Correct 188 ms 5332 KB Output is correct
11 Correct 198 ms 5844 KB Output is correct
12 Correct 247 ms 6432 KB Output is correct
13 Correct 210 ms 6536 KB Output is correct
14 Correct 197 ms 6536 KB Output is correct
15 Correct 239 ms 6536 KB Output is correct
16 Correct 210 ms 6536 KB Output is correct
17 Correct 221 ms 6692 KB Output is correct
18 Correct 213 ms 6692 KB Output is correct
19 Correct 215 ms 6692 KB Output is correct
20 Correct 204 ms 6692 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 2 ms 412 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 536 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 ms 752 KB Output is correct
10 Correct 5 ms 752 KB Output is correct
11 Correct 4 ms 752 KB Output is correct
12 Correct 5 ms 780 KB Output is correct
13 Correct 5 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 6 ms 780 KB Output is correct
16 Correct 3 ms 780 KB Output is correct
17 Correct 4 ms 780 KB Output is correct
18 Correct 4 ms 780 KB Output is correct
19 Correct 15 ms 1084 KB Output is correct
20 Correct 30 ms 1596 KB Output is correct
21 Correct 47 ms 2120 KB Output is correct
22 Correct 73 ms 2772 KB Output is correct
23 Correct 90 ms 3412 KB Output is correct
24 Correct 152 ms 5332 KB Output is correct
25 Correct 188 ms 5332 KB Output is correct
26 Correct 198 ms 5844 KB Output is correct
27 Correct 247 ms 6432 KB Output is correct
28 Correct 210 ms 6536 KB Output is correct
29 Correct 197 ms 6536 KB Output is correct
30 Correct 239 ms 6536 KB Output is correct
31 Correct 210 ms 6536 KB Output is correct
32 Correct 221 ms 6692 KB Output is correct
33 Correct 213 ms 6692 KB Output is correct
34 Correct 215 ms 6692 KB Output is correct
35 Correct 204 ms 6692 KB Output is correct
36 Correct 4 ms 6692 KB Output is correct
37 Correct 3 ms 6692 KB Output is correct
38 Correct 4 ms 6692 KB Output is correct
39 Correct 19 ms 6692 KB Output is correct
40 Correct 31 ms 6692 KB Output is correct
41 Correct 66 ms 6692 KB Output is correct
42 Correct 98 ms 6692 KB Output is correct
43 Correct 131 ms 6692 KB Output is correct
44 Correct 205 ms 6692 KB Output is correct
45 Correct 196 ms 6692 KB Output is correct
46 Correct 183 ms 6692 KB Output is correct
47 Correct 260 ms 6692 KB Output is correct
48 Correct 257 ms 6772 KB Output is correct
49 Correct 355 ms 6772 KB Output is correct
50 Correct 254 ms 6772 KB Output is correct
51 Correct 291 ms 6904 KB Output is correct
52 Correct 297 ms 6904 KB Output is correct
53 Correct 242 ms 6904 KB Output is correct
54 Correct 249 ms 6904 KB Output is correct
55 Correct 263 ms 6904 KB Output is correct