Submission #143500

# Submission time Handle Problem Language Result Execution time Memory
143500 2019-08-14T11:37:44 Z songc Employment (JOI16_employment) C++14
100 / 100
589 ms 14948 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, Q;
int qu[202020], X[202020], Y[202020];
int A[202020];
int T[1505050];
vector<int> comp;

int com(int x){return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1;}

void update(int id, int s, int e, int ts, int te, int v){
	if (e < ts || te < s) return;
	if (ts <= s && e <= te){
		T[id] += v;
		return;
	}

	int mid = (s+e)/2;
	update(id*2, s, mid, ts, te, v);
	update(id*2+1, mid+1, e, ts, te, v);
}

int query(int id, int s, int e, int t){
	if (e < t || t < s) return 0;
	if (s == e) return T[id];
	int mid = (s+e)/2;
	return query(id*2, s, mid, t) + query(id*2+1, mid+1, e, t) + T[id];
}

int main(){
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++){
		scanf("%d", &A[i]);
		comp.push_back(A[i]);
	}
	for (int i=1; i<=Q; i++){
		scanf("%d", &qu[i]);
		scanf("%d", &X[i]);
		comp.push_back(X[i]);
		if (qu[i] == 2){
			scanf("%d", &Y[i]);
			comp.push_back(Y[i]);
		}
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for (int i=1; i<=N; i++) {
		A[i] = com(A[i]);
		update(1, 1, comp.size(), min(A[i], A[i-1])+1, max(A[i], A[i-1]), 1);
	}
	update(1, 1, comp.size(), 1, A[N], 1);
	for (int i=1; i<=Q; i++){
		if (qu[i] == 1) printf("%d\n", query(1, 1, comp.size(), com(X[i])) / 2);
		else {
			update(1, 1, comp.size(), min(A[X[i]], A[X[i]-1])+1, max(A[X[i]], A[X[i]-1]), -1);
			update(1, 1, comp.size(), min(A[X[i]], A[X[i]+1])+1, max(A[X[i]], A[X[i]+1]), -1);
			A[X[i]] = com(Y[i]);
			update(1, 1, comp.size(), min(A[X[i]], A[X[i]-1])+1, max(A[X[i]], A[X[i]-1]), 1);
			update(1, 1, comp.size(), min(A[X[i]], A[X[i]+1])+1, max(A[X[i]], A[X[i]+1]), 1);
		}
	}
	return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~
employment.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &qu[i]);
   ~~~~~^~~~~~~~~~~~~~
employment.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &X[i]);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &Y[i]);
    ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 508 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 26 ms 1528 KB Output is correct
5 Correct 55 ms 2420 KB Output is correct
6 Correct 84 ms 3796 KB Output is correct
7 Correct 138 ms 6000 KB Output is correct
8 Correct 191 ms 6892 KB Output is correct
9 Correct 301 ms 12004 KB Output is correct
10 Correct 282 ms 11136 KB Output is correct
11 Correct 371 ms 13008 KB Output is correct
12 Correct 392 ms 13820 KB Output is correct
13 Correct 398 ms 13928 KB Output is correct
14 Correct 383 ms 13668 KB Output is correct
15 Correct 385 ms 13668 KB Output is correct
16 Correct 394 ms 14052 KB Output is correct
17 Correct 398 ms 13924 KB Output is correct
18 Correct 398 ms 14056 KB Output is correct
19 Correct 399 ms 14052 KB Output is correct
20 Correct 394 ms 14084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 5 ms 508 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 26 ms 1528 KB Output is correct
20 Correct 55 ms 2420 KB Output is correct
21 Correct 84 ms 3796 KB Output is correct
22 Correct 138 ms 6000 KB Output is correct
23 Correct 191 ms 6892 KB Output is correct
24 Correct 301 ms 12004 KB Output is correct
25 Correct 282 ms 11136 KB Output is correct
26 Correct 371 ms 13008 KB Output is correct
27 Correct 392 ms 13820 KB Output is correct
28 Correct 398 ms 13928 KB Output is correct
29 Correct 383 ms 13668 KB Output is correct
30 Correct 385 ms 13668 KB Output is correct
31 Correct 394 ms 14052 KB Output is correct
32 Correct 398 ms 13924 KB Output is correct
33 Correct 398 ms 14056 KB Output is correct
34 Correct 399 ms 14052 KB Output is correct
35 Correct 394 ms 14084 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 6 ms 504 KB Output is correct
38 Correct 7 ms 632 KB Output is correct
39 Correct 37 ms 1776 KB Output is correct
40 Correct 70 ms 2928 KB Output is correct
41 Correct 123 ms 3952 KB Output is correct
42 Correct 177 ms 5884 KB Output is correct
43 Correct 246 ms 7172 KB Output is correct
44 Correct 465 ms 12712 KB Output is correct
45 Correct 381 ms 11272 KB Output is correct
46 Correct 419 ms 11784 KB Output is correct
47 Correct 576 ms 14528 KB Output is correct
48 Correct 582 ms 14688 KB Output is correct
49 Correct 579 ms 14820 KB Output is correct
50 Correct 574 ms 14356 KB Output is correct
51 Correct 584 ms 14864 KB Output is correct
52 Correct 587 ms 14920 KB Output is correct
53 Correct 589 ms 14796 KB Output is correct
54 Correct 586 ms 14948 KB Output is correct
55 Correct 579 ms 14692 KB Output is correct