이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int mx,n,i,a[1000001],ans,tree[4000004];
void update(int v,int l,int r,int pos,int val){
if(l==pos&&r==pos){
tree[v]=val;
return;
}
int mid=(l+r)>>1;
if(pos<=mid)update((v*2),l,mid,pos,val);
else update((v*2)+1,mid+1,r,pos,val);
tree[v]=min(tree[(v*2)],tree[(v*2)+1]);
}
int get(int v,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr)return tree[v];
if(r<ql||qr<l)return 1000001;
int mid=(l+r)>>1;
return min(get((v*2),l,mid,ql,qr),get((v*2)+1,mid+1,r,ql,qr));
}
main(){
for(i=0;i<4000004;i++)tree[i]=1000001;
scanf("%lld",&n);
for(i=0;i<n;i++)scanf("%lld",&a[i]);
i=0;
while(i<n){
mx=get(1,1,1000001,a[i]+1,1000001);
update(1,1,1000001,a[i],a[i]);
while(i+1<n&&a[i]<=a[i+1]&&a[i+1]<=mx)i++,update(1,1,1000001,a[i],a[i]);;
i++;
ans++;
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
money.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
money.cpp: In function 'int main()':
money.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
money.cpp:25:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=0;i<n;i++)scanf("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |