# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
257911 |
2020-08-05T04:29:22 Z |
송준혁(#5048) |
Employment (JOI16_employment) |
C++17 |
|
295 ms |
11620 KB |
#include <bits/stdc++.h>
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define mup(a,x) a=min(a,x)
#define Mup(a,x) a=max(a,x)
#define INF 1234567890
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, Q;
int A[202020], qt[202020], R[202020];
int T[404040];
vector<int> V;
void upd(int k, int v){for(;k<=V.size(); k+=k&-k) T[k]+=v;}
int read(int k){int r=0; for(;k; k^=k&-k) r+=T[k]; return r;}
int main(){
scanf("%d %d", &N, &Q);
for (int i=1; i<=N; i++) scanf("%d", &A[i]), V.pb(A[i]);
for (int i=1; i<=Q; i++){
scanf("%d", &qt[i]);
if (qt[i] == 1) scanf("%d", &R[i]), qt[i]=0;
else scanf("%d %d", &qt[i], &R[i]);
V.pb(R[i]);
}
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
for (int i=1; i<=N; i++) A[i] = lower_bound(V.begin(), V.end(), A[i])-V.begin()+1;
for (int i=0; i<=N; i++) upd(min(A[i], A[i+1])+1, 1), upd(max(A[i], A[i+1])+1, -1);
for (int i=1; i<=Q; i++){
R[i] = lower_bound(V.begin(), V.end(), R[i])-V.begin()+1;
if (qt[i]){
int x=qt[i];
upd(min(A[x-1], A[x])+1, -1), upd(max(A[x-1], A[x])+1, 1);
upd(min(A[x], A[x+1])+1, -1), upd(max(A[x], A[x+1])+1, 1);
A[x] = R[i];
upd(min(A[x-1], A[x])+1, 1), upd(max(A[x-1], A[x])+1, -1);
upd(min(A[x], A[x+1])+1, 1), upd(max(A[x], A[x+1])+1, -1);
}
else printf("%d\n", read(R[i])/2);
}
return 0;
}
Compilation message
employment.cpp: In function 'void upd(int, int)':
employment.cpp:18:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
void upd(int k, int v){for(;k<=V.size(); k+=k&-k) T[k]+=v;}
~^~~~~~~~~~
employment.cpp: In function 'int main()':
employment.cpp:22: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:23:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%d", &A[i]), V.pb(A[i]);
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
employment.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &qt[i]);
~~~~~^~~~~~~~~~~~~~
employment.cpp:26:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if (qt[i] == 1) scanf("%d", &R[i]), qt[i]=0;
~~~~~~~~~~~~~~~~~~^~~~~~~~~
employment.cpp:27:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
else scanf("%d %d", &qt[i], &R[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 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 |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
1024 KB |
Output is correct |
5 |
Correct |
34 ms |
1396 KB |
Output is correct |
6 |
Correct |
59 ms |
2068 KB |
Output is correct |
7 |
Correct |
84 ms |
2924 KB |
Output is correct |
8 |
Correct |
110 ms |
3560 KB |
Output is correct |
9 |
Correct |
186 ms |
5876 KB |
Output is correct |
10 |
Correct |
164 ms |
4836 KB |
Output is correct |
11 |
Correct |
218 ms |
6504 KB |
Output is correct |
12 |
Correct |
253 ms |
7164 KB |
Output is correct |
13 |
Correct |
240 ms |
7012 KB |
Output is correct |
14 |
Correct |
250 ms |
6884 KB |
Output is correct |
15 |
Correct |
233 ms |
6884 KB |
Output is correct |
16 |
Correct |
243 ms |
7084 KB |
Output is correct |
17 |
Correct |
242 ms |
7288 KB |
Output is correct |
18 |
Correct |
239 ms |
7140 KB |
Output is correct |
19 |
Correct |
242 ms |
7140 KB |
Output is correct |
20 |
Correct |
239 ms |
7140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 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 |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
436 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
17 ms |
1024 KB |
Output is correct |
20 |
Correct |
34 ms |
1396 KB |
Output is correct |
21 |
Correct |
59 ms |
2068 KB |
Output is correct |
22 |
Correct |
84 ms |
2924 KB |
Output is correct |
23 |
Correct |
110 ms |
3560 KB |
Output is correct |
24 |
Correct |
186 ms |
5876 KB |
Output is correct |
25 |
Correct |
164 ms |
4836 KB |
Output is correct |
26 |
Correct |
218 ms |
6504 KB |
Output is correct |
27 |
Correct |
253 ms |
7164 KB |
Output is correct |
28 |
Correct |
240 ms |
7012 KB |
Output is correct |
29 |
Correct |
250 ms |
6884 KB |
Output is correct |
30 |
Correct |
233 ms |
6884 KB |
Output is correct |
31 |
Correct |
243 ms |
7084 KB |
Output is correct |
32 |
Correct |
242 ms |
7288 KB |
Output is correct |
33 |
Correct |
239 ms |
7140 KB |
Output is correct |
34 |
Correct |
242 ms |
7140 KB |
Output is correct |
35 |
Correct |
239 ms |
7140 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
516 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
19 ms |
1280 KB |
Output is correct |
40 |
Correct |
35 ms |
2044 KB |
Output is correct |
41 |
Correct |
61 ms |
3056 KB |
Output is correct |
42 |
Correct |
87 ms |
4204 KB |
Output is correct |
43 |
Correct |
132 ms |
5480 KB |
Output is correct |
44 |
Correct |
221 ms |
9428 KB |
Output is correct |
45 |
Correct |
180 ms |
7780 KB |
Output is correct |
46 |
Correct |
223 ms |
8704 KB |
Output is correct |
47 |
Correct |
266 ms |
11136 KB |
Output is correct |
48 |
Correct |
275 ms |
11376 KB |
Output is correct |
49 |
Correct |
278 ms |
11272 KB |
Output is correct |
50 |
Correct |
278 ms |
11108 KB |
Output is correct |
51 |
Correct |
277 ms |
11492 KB |
Output is correct |
52 |
Correct |
279 ms |
11620 KB |
Output is correct |
53 |
Correct |
284 ms |
11384 KB |
Output is correct |
54 |
Correct |
295 ms |
11424 KB |
Output is correct |
55 |
Correct |
288 ms |
11428 KB |
Output is correct |