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>
const int MOD = 1e9+7;
using namespace std;
struct ball {
int c, l, r;
};
void solve(){
int n;
cin >> n;
int a[n];
for(int i = 0;i < n;i++) cin >> a[i];
map<int, int> c;
stack<ball> s;
for(int i = 0;i < n;i++){
ball g = {a[i], i, i};
if(!c[a[i]]){
c[a[i]]++;
s.push(g);
continue;
}
while(s.top().c != a[i]){
g.l = s.top().l;
c[s.top().c] -= s.top().r-s.top().l+1;
s.pop();
}
c[a[i]] += g.r-g.l+1;
g.l = s.top().l;
s.pop();
s.push(g);
}
while(!s.empty()){
for(int i = s.top().l;i <= s.top().r;i++) a[i] = s.top().c;
s.pop();
}
for(int i = 0;i < n;i++) cout << a[i] << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |