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>
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef __int128 lll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
const ll mn=1e6+10;
ll a[mn];
bool gud[mn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
int ans=0;
stack<int>s;
int ma=-1;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=ans,a[i]%=(int)1e9;
if(a[i]>ma)gud[i]=1;
ma=max(ma,(int)a[i]);
while(s.size()&&a[i]<=a[s.top()]){
gud[i]=0;
ans-=gud[s.top()];
s.pop();
}
s.push(i),ans+=gud[i];
printf("%d\n",ans);
}
}
# | 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... |