이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int N,M, h[MAXN];
int marc[MAXN];
int main()
{
cin>>N>>M;
for(int i = 1; i <= N; i++)cin>>h[i];
for(int i = 1; i <= N; i++)
{
if(i==N)
{
marc[h[i]]++;
break;
}
int s = min(h[i],h[i+1]), f = max(h[i],h[i+1]);
if(s==f)
{
marc[s]++;
continue;
}
for(int k = s; k < f; k++)marc[k]++;
}
for(int m = 1; m <= M; m++)
{
int q; cin>>q;
if(q==1)
{
int p,v; cin>>p>>v;
if(p==N) marc[h[p]]--;
else
{
int ls = min(h[p],h[p+1]), lf = max(h[p],h[p+1]);
for(int k = ls; k < lf; k++)marc[k]--;
int s = min(v,h[p+1]), f = max(v,h[p+1]);
for(int k = s; k < f; k++)marc[k]++;
}
if(p!=1)
{
int ls = min(h[p],h[p-1]), lf = max(h[p],h[p-1]);
for(int k = ls; k < lf; k++)marc[k]--;
int s = min(v,h[p-1]), f = max(v,h[p-1]);
for(int k = s; k < f; k++)marc[k]++;
}
h[p]=v;
}
else
{
int x; cin>>x;
cout<<marc[x]<<"\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... |