# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
257949 |
2020-08-05T05:54:05 Z |
임성재(#5053) |
Employment (JOI16_employment) |
C++17 |
|
237 ms |
7416 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, q;
int a[200010];
int t[200010];
int b[200010];
int c[200010];
int tree[401010];
vector<int> v;
void update(int i, int x) {
//cout << i << "!!! " << x << endl;
while(i <= 400010) {
tree[i] += x;
i += i & -i;
}
}
int sum(int i) {
int ret = 0;
while(i) {
ret += tree[i];
i -= i & -i;
}
return ret;
}
bool up(int x) {
if(x < 1 || x > n) return false;
if(a[x-1] < a[x] && a[x] >= a[x+1]) return true;
return false;
}
bool down(int x) {
if(x < 1 || x > n) return false;
if(a[x-1] >= a[x] && a[x] < a[x+1]) return true;
return false;
}
int main() {
fast;
cin >> n >> q;
for(int i=1; i<=n; i++) {
cin >> a[i];
v.eb(a[i]);
}
for(int i=1; i<=q; i++) {
cin >> t[i];
if(t[i] == 2) cin >> b[i];
cin >> c[i];
v.eb(c[i]);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
for(int i=1; i<=n; i++) {
a[i] = lower_bound(all(v), a[i]) - v.begin() + 1;
}
for(int i=1; i<=n; i++) {
if(up(i)) update(a[i]+1, -1);
if(down(i)) update(a[i]+1, 1);
}
for(int i=1; i<=q; i++) {
c[i] = lower_bound(all(v), c[i]) - v.begin() + 1;
if(t[i] == 1) {
cout << sum(c[i]) + 1 << "\n";
}
else {
if(up(b[i])) update(a[b[i]]+1, 1);
if(down(b[i])) update(a[b[i]]+1, -1);
if(up(b[i]+1)) update(a[b[i]+1]+1, 1);
if(down(b[i]+1)) update(a[b[i]+1]+1, -1);
if(up(b[i]-1)) update(a[b[i]-1]+1, 1);
if(down(b[i]-1)) update(a[b[i]-1]+1, -1);
a[b[i]] = c[i];
if(up(b[i])) update(a[b[i]]+1, -1);
if(down(b[i])) update(a[b[i]]+1, 1);
if(up(b[i]+1)) update(a[b[i]+1]+1, -1);
if(down(b[i]+1)) update(a[b[i]+1]+1, 1);
if(up(b[i]-1)) update(a[b[i]-1]+1, -1);
if(down(b[i]-1)) update(a[b[i]-1]+1, 1);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
15 ms |
1024 KB |
Output is correct |
5 |
Correct |
29 ms |
1528 KB |
Output is correct |
6 |
Correct |
47 ms |
2164 KB |
Output is correct |
7 |
Correct |
74 ms |
3196 KB |
Output is correct |
8 |
Correct |
90 ms |
3692 KB |
Output is correct |
9 |
Correct |
165 ms |
5864 KB |
Output is correct |
10 |
Correct |
144 ms |
4948 KB |
Output is correct |
11 |
Correct |
194 ms |
6504 KB |
Output is correct |
12 |
Correct |
212 ms |
7016 KB |
Output is correct |
13 |
Correct |
203 ms |
7016 KB |
Output is correct |
14 |
Correct |
214 ms |
7016 KB |
Output is correct |
15 |
Correct |
201 ms |
7016 KB |
Output is correct |
16 |
Correct |
215 ms |
7272 KB |
Output is correct |
17 |
Correct |
216 ms |
7400 KB |
Output is correct |
18 |
Correct |
204 ms |
7144 KB |
Output is correct |
19 |
Correct |
208 ms |
7272 KB |
Output is correct |
20 |
Correct |
202 ms |
7144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
15 ms |
1024 KB |
Output is correct |
20 |
Correct |
29 ms |
1528 KB |
Output is correct |
21 |
Correct |
47 ms |
2164 KB |
Output is correct |
22 |
Correct |
74 ms |
3196 KB |
Output is correct |
23 |
Correct |
90 ms |
3692 KB |
Output is correct |
24 |
Correct |
165 ms |
5864 KB |
Output is correct |
25 |
Correct |
144 ms |
4948 KB |
Output is correct |
26 |
Correct |
194 ms |
6504 KB |
Output is correct |
27 |
Correct |
212 ms |
7016 KB |
Output is correct |
28 |
Correct |
203 ms |
7016 KB |
Output is correct |
29 |
Correct |
214 ms |
7016 KB |
Output is correct |
30 |
Correct |
201 ms |
7016 KB |
Output is correct |
31 |
Correct |
215 ms |
7272 KB |
Output is correct |
32 |
Correct |
216 ms |
7400 KB |
Output is correct |
33 |
Correct |
204 ms |
7144 KB |
Output is correct |
34 |
Correct |
208 ms |
7272 KB |
Output is correct |
35 |
Correct |
202 ms |
7144 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
16 ms |
1024 KB |
Output is correct |
40 |
Correct |
30 ms |
1528 KB |
Output is correct |
41 |
Correct |
52 ms |
2164 KB |
Output is correct |
42 |
Correct |
74 ms |
2804 KB |
Output is correct |
43 |
Correct |
99 ms |
3696 KB |
Output is correct |
44 |
Correct |
191 ms |
5992 KB |
Output is correct |
45 |
Correct |
155 ms |
5160 KB |
Output is correct |
46 |
Correct |
168 ms |
5608 KB |
Output is correct |
47 |
Correct |
223 ms |
7148 KB |
Output is correct |
48 |
Correct |
229 ms |
7400 KB |
Output is correct |
49 |
Correct |
222 ms |
7272 KB |
Output is correct |
50 |
Correct |
221 ms |
7148 KB |
Output is correct |
51 |
Correct |
226 ms |
7400 KB |
Output is correct |
52 |
Correct |
230 ms |
7400 KB |
Output is correct |
53 |
Correct |
229 ms |
7272 KB |
Output is correct |
54 |
Correct |
237 ms |
7356 KB |
Output is correct |
55 |
Correct |
235 ms |
7416 KB |
Output is correct |