이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000007
#define INF 1000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
const int Max = 1e6 + 5;
const int M = 1e6;
int cnt[Max];
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n, m; cin >> n >> m; int arr[n];
for(int i = 0; i < n; i++) cin >> arr[i];
for(int i = 1; i < n; i++) {
if(arr[i-1] < arr[i]) {
cnt[arr[i-1]]++;
cnt[arr[i]+1]--;
}
else if(arr[i-1] != arr[i]) {
cnt[arr[i-1]]--;
cnt[arr[i]+1]++;
}
}
for(int i = 1; i <= M; i++) {
cnt[i] += cnt[i-1];
}
if(n <= 1000)
{
while(m--) {
int ty; cin >> ty;
if(ty == 1) {
int pos, val; cin >> pos >> val;
arr[pos-1] = val;
}
else {
int h, ans = 0; cin >> h; bool ok;
if(arr[0] < h) ok = false;
else ok = true;
for(int i = 1; i < n; i++) {
if(arr[i] > h && ok == false) {
ans++; ok = true;
}
else if(arr[i] < h && ok == true) {
ans++; ok = false;
}
}
cout << ans << endl;
}
}}
else {
while(m--) {
int ty; cin >> ty;
if(ty == 1) {
int pos, val; cin >> pos >> val;
arr[pos-1] = val;
}
else {
int h; cin >> h;
cout << cnt[h] << endl;
}
}
}
return 0;
}
/*3 3
1 5 1
2 3
1 1 5
2 3*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |