-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaux.cpp
More file actions
44 lines (40 loc) · 687 Bytes
/
Copy pathaux.cpp
File metadata and controls
44 lines (40 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
#define ll long long
const int maxi = 500100;
vector<int>a(maxi);
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int t; cin>>t;
for(int j=1; j<=t; j++){
int n; cin>>n;
for(int i =0; i<n ;i++){
cin>>a[i];
}
stack<int>s;
vector<int>ans(n+1);
for(int i =0; i<n ;i++){
while(s.size() && (a[i] > a[s.top()])){
ans[s.top()] = a[i];
s.pop();
}
s.push(i);
}
while(s.size()){
s.pop();
}
for(int i =0; i<n ;i++){
if(ans[i] == 0){
ans[i] = -1;
}
}
cout<<"Case #"<<j<<": ";
for(int i =0; i<n ;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
return 0;
}