# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
257953 |
2020-08-05T06:01:04 Z |
반딧불(#5055) |
Employment (JOI16_employment) |
C++17 |
|
293 ms |
9212 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, q, k;
int arr[200002];
int qt[200002], qa[200002], qb[200002];
vector<int> renumberVec;
int tree[400002];
int findTree(int x){
int ret = 0;
while(x){
ret += tree[x];
x -= x & (-x);
}
return ret;
}
void update(int l, int x){
while(l <= k){
tree[l] += x;
l += l & (-l);
}
}
void update(int l, int r, int x){
if(l>r) return;
update(l, x);
update(r+1, -x);
}
void initializeTree(){
vector<pair<int, int> > vec;
vector<int> used (n+2, 0);
int cnt = 0;
for(int i=1; i<=n; i++){
vec.push_back(make_pair(arr[i], i));
}
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
int pnt = 0;
for(int i=k; i>=1; i--){
while(pnt < n && vec[pnt].first == i){
int x = vec[pnt].second;
if(used[x-1] && used[x+1]) cnt--;
else if(!used[x-1] && !used[x+1]) cnt++;
used[x] = 1;
pnt++;
}
update(i, i, cnt);
}
}
int main(){
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++){
scanf("%d", &arr[i]);
renumberVec.push_back(arr[i]);
}
for(int i=1; i<=q; i++){
scanf("%d %d", &qt[i], &qa[i]);
if(qt[i] == 1) renumberVec.push_back(qa[i]);
else{
scanf("%d", &qb[i]);
renumberVec.push_back(qb[i]);
}
}
sort(renumberVec.begin(), renumberVec.end());
renumberVec.erase(unique(renumberVec.begin(), renumberVec.end()), renumberVec.end());
k = (int)renumberVec.size();
for(int i=1; i<=n; i++){
arr[i] = lower_bound(renumberVec.begin(), renumberVec.end(), arr[i]) - renumberVec.begin() + 1;
}
for(int i=1; i<=q; i++){
if(qt[i] == 1) qa[i] = lower_bound(renumberVec.begin(), renumberVec.end(), qa[i]) - renumberVec.begin() + 1;
else qb[i] = lower_bound(renumberVec.begin(), renumberVec.end(), qb[i]) - renumberVec.begin() + 1;
}
initializeTree();
for(int i=1; i<=q; i++){
if(qt[i] == 1){
printf("%d\n", findTree(qa[i]));
continue;
}
int x = qa[i], y = qb[i];
if(arr[x] >= arr[x+1] && arr[x] >= arr[x-1]){
update(max(arr[x-1], arr[x+1])+1, arr[x], -1);
update(1, min(arr[x-1], arr[x+1]), 1);
}
else{
update(1, min({arr[x], arr[x-1], arr[x+1]}), 1);
}
arr[x] = y;
if(arr[x] >= arr[x+1] && arr[x] >= arr[x-1]){
update(max(arr[x-1], arr[x+1])+1, arr[x], 1);
update(1, min(arr[x-1], arr[x+1]), -1);
}
else{
update(1, min({arr[x], arr[x-1], arr[x+1]}), -1);
}
}
}
Compilation message
employment.cpp: In function 'int main()':
employment.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
employment.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
employment.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &qt[i], &qa[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
employment.cpp:67:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &qb[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 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 |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
26 ms |
1024 KB |
Output is correct |
5 |
Correct |
37 ms |
1780 KB |
Output is correct |
6 |
Correct |
57 ms |
2296 KB |
Output is correct |
7 |
Correct |
92 ms |
3692 KB |
Output is correct |
8 |
Correct |
117 ms |
4096 KB |
Output is correct |
9 |
Correct |
197 ms |
7012 KB |
Output is correct |
10 |
Correct |
181 ms |
6884 KB |
Output is correct |
11 |
Correct |
225 ms |
7616 KB |
Output is correct |
12 |
Correct |
258 ms |
8160 KB |
Output is correct |
13 |
Correct |
258 ms |
8288 KB |
Output is correct |
14 |
Correct |
253 ms |
8036 KB |
Output is correct |
15 |
Correct |
286 ms |
8168 KB |
Output is correct |
16 |
Correct |
255 ms |
8288 KB |
Output is correct |
17 |
Correct |
258 ms |
8292 KB |
Output is correct |
18 |
Correct |
256 ms |
8288 KB |
Output is correct |
19 |
Correct |
262 ms |
8292 KB |
Output is correct |
20 |
Correct |
258 ms |
8296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 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 |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
26 ms |
1024 KB |
Output is correct |
20 |
Correct |
37 ms |
1780 KB |
Output is correct |
21 |
Correct |
57 ms |
2296 KB |
Output is correct |
22 |
Correct |
92 ms |
3692 KB |
Output is correct |
23 |
Correct |
117 ms |
4096 KB |
Output is correct |
24 |
Correct |
197 ms |
7012 KB |
Output is correct |
25 |
Correct |
181 ms |
6884 KB |
Output is correct |
26 |
Correct |
225 ms |
7616 KB |
Output is correct |
27 |
Correct |
258 ms |
8160 KB |
Output is correct |
28 |
Correct |
258 ms |
8288 KB |
Output is correct |
29 |
Correct |
253 ms |
8036 KB |
Output is correct |
30 |
Correct |
286 ms |
8168 KB |
Output is correct |
31 |
Correct |
255 ms |
8288 KB |
Output is correct |
32 |
Correct |
258 ms |
8292 KB |
Output is correct |
33 |
Correct |
256 ms |
8288 KB |
Output is correct |
34 |
Correct |
262 ms |
8292 KB |
Output is correct |
35 |
Correct |
258 ms |
8296 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
3 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
24 ms |
1204 KB |
Output is correct |
40 |
Correct |
37 ms |
1620 KB |
Output is correct |
41 |
Correct |
66 ms |
2416 KB |
Output is correct |
42 |
Correct |
95 ms |
3852 KB |
Output is correct |
43 |
Correct |
133 ms |
4352 KB |
Output is correct |
44 |
Correct |
235 ms |
7908 KB |
Output is correct |
45 |
Correct |
192 ms |
7140 KB |
Output is correct |
46 |
Correct |
209 ms |
7524 KB |
Output is correct |
47 |
Correct |
276 ms |
8928 KB |
Output is correct |
48 |
Correct |
277 ms |
8928 KB |
Output is correct |
49 |
Correct |
288 ms |
9188 KB |
Output is correct |
50 |
Correct |
272 ms |
8800 KB |
Output is correct |
51 |
Correct |
280 ms |
9060 KB |
Output is correct |
52 |
Correct |
285 ms |
9060 KB |
Output is correct |
53 |
Correct |
293 ms |
9056 KB |
Output is correct |
54 |
Correct |
289 ms |
9056 KB |
Output is correct |
55 |
Correct |
285 ms |
9212 KB |
Output is correct |