This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
const int N = 100100;
int TN = 1;
multiset<pair<int, int> > st;
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
/// -------------------------------------
// fin("game.in"); fout("game.out");
/// cin >> TN;
/// -------------------------------------
int n, m;
cin >> n >> m;
if (n <= 1000 && m <= 1000) {
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int t, pos, new_val, x;
for (int i = 1; i <= m; i++) {
cin >> t;
if (t == 1) {
cin >> pos >> new_val;
a[pos] = new_val;
}
else {
int cnt = 0;
cin >> x;
for (int j = 1; j < n; j++) {
if ((a[j] <= x && x <= a[j + 1]) || (a[j + 1] <= x && x <= a[j])) {
cnt++;
}
}
cout << cnt << endl;
}
}
return 0;
}
else {
multiset<pair<int, int> > st;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1) {
st.insert(make_pair(min(a[i], a[i - 1]), 0));
st.insert(make_pair(max(a[i], a[i - 1]), INT_MAX));
}
}
int t, h;
for (int i = 1; i <= m; i++) {
cin >> t;
if (t == 2) {
cin >> h;
st.insert(make_pair(h, i));
}
}
multiset<pair<int, int> > :: iterator it;
vector<int> ans(N);
int cnt = 0;
for (it = st.begin(); it != st.end(); it++) {
pair<int, int> p = *it;
if (p.second == 0) cnt++;
if (p.second > 0 && p.second < INT_MAX) ans[p.second] = cnt;
if (p.second == INT_MAX) cnt--;
}
for (int i = 1; i <= m; i++) {
cout << ans[i] << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |