답안 #53725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53725 2018-07-01T05:59:54 Z ainta(#1540) Employment (JOI16_employment) C++11
100 / 100
368 ms 122012 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);
    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 4 ms 812 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 4 ms 836 KB Output is correct
11 Correct 4 ms 956 KB Output is correct
12 Correct 5 ms 956 KB Output is correct
13 Correct 4 ms 956 KB Output is correct
14 Correct 4 ms 1068 KB Output is correct
15 Correct 4 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1124 KB Output is correct
2 Correct 4 ms 1124 KB Output is correct
3 Correct 5 ms 1124 KB Output is correct
4 Correct 18 ms 1932 KB Output is correct
5 Correct 31 ms 2920 KB Output is correct
6 Correct 46 ms 4600 KB Output is correct
7 Correct 75 ms 6940 KB Output is correct
8 Correct 122 ms 9424 KB Output is correct
9 Correct 153 ms 14640 KB Output is correct
10 Correct 221 ms 17156 KB Output is correct
11 Correct 310 ms 22092 KB Output is correct
12 Correct 308 ms 27004 KB Output is correct
13 Correct 211 ms 31036 KB Output is correct
14 Correct 208 ms 35084 KB Output is correct
15 Correct 214 ms 39340 KB Output is correct
16 Correct 216 ms 43676 KB Output is correct
17 Correct 243 ms 48044 KB Output is correct
18 Correct 240 ms 52316 KB Output is correct
19 Correct 227 ms 56588 KB Output is correct
20 Correct 275 ms 60908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 4 ms 812 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 4 ms 836 KB Output is correct
11 Correct 4 ms 956 KB Output is correct
12 Correct 5 ms 956 KB Output is correct
13 Correct 4 ms 956 KB Output is correct
14 Correct 4 ms 1068 KB Output is correct
15 Correct 4 ms 1068 KB Output is correct
16 Correct 3 ms 1124 KB Output is correct
17 Correct 4 ms 1124 KB Output is correct
18 Correct 5 ms 1124 KB Output is correct
19 Correct 18 ms 1932 KB Output is correct
20 Correct 31 ms 2920 KB Output is correct
21 Correct 46 ms 4600 KB Output is correct
22 Correct 75 ms 6940 KB Output is correct
23 Correct 122 ms 9424 KB Output is correct
24 Correct 153 ms 14640 KB Output is correct
25 Correct 221 ms 17156 KB Output is correct
26 Correct 310 ms 22092 KB Output is correct
27 Correct 308 ms 27004 KB Output is correct
28 Correct 211 ms 31036 KB Output is correct
29 Correct 208 ms 35084 KB Output is correct
30 Correct 214 ms 39340 KB Output is correct
31 Correct 216 ms 43676 KB Output is correct
32 Correct 243 ms 48044 KB Output is correct
33 Correct 240 ms 52316 KB Output is correct
34 Correct 227 ms 56588 KB Output is correct
35 Correct 275 ms 60908 KB Output is correct
36 Correct 5 ms 60908 KB Output is correct
37 Correct 6 ms 60908 KB Output is correct
38 Correct 6 ms 60908 KB Output is correct
39 Correct 20 ms 60908 KB Output is correct
40 Correct 55 ms 60908 KB Output is correct
41 Correct 88 ms 60908 KB Output is correct
42 Correct 128 ms 61152 KB Output is correct
43 Correct 163 ms 64188 KB Output is correct
44 Correct 277 ms 70308 KB Output is correct
45 Correct 267 ms 72600 KB Output is correct
46 Correct 277 ms 76692 KB Output is correct
47 Correct 327 ms 82772 KB Output is correct
48 Correct 316 ms 87816 KB Output is correct
49 Correct 368 ms 92660 KB Output is correct
50 Correct 305 ms 97164 KB Output is correct
51 Correct 325 ms 102316 KB Output is correct
52 Correct 273 ms 107212 KB Output is correct
53 Correct 323 ms 112080 KB Output is correct
54 Correct 346 ms 117072 KB Output is correct
55 Correct 308 ms 122012 KB Output is correct