이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
const int N = (int)1e6 + 1;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (auto &i : a)
cin >> i;
if (n <= (int)1e3) {
while (q--) {
int tp, x;
cin >> tp >> x;
if (tp == 1) {
int vl;
cin >> vl;
a[--x] = vl;
}
else {
int cnt = 0;
for (int i = 0; i + 1 < n; i++)
cnt += (min(a[i], a[i + 1]) < x && x < max(a[i], a[i + 1]));
cout << cnt << '\n';
}
}
return 0;
}
vector<int> cnt(N);
for (int i = 0; i + 1 < n; i++)
cnt[min(a[i], a[i + 1])]++;
for (int i = N - 2; i >= 0; i--)
cnt[i] += cnt[i + 1];
sort(all(a));
while (q--) {
int tp, x;
cin >> tp >> x;
int y = upper_bound(all(a), x) - a.begin();
cout << (y == n ? 0 : (x < a[n - 1]) + ((n - y - 1 - cnt[a[y]]) << 1)) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |