Submission #983136

#TimeUsernameProblemLanguageResultExecution timeMemory
983136MalixStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
548 ms150404 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; typedef vector<pi> pii; #define REP(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define PB push_back #define MP make_pair ll INF=1e18+10; ll M=1e9+7; int main() { //ios::sync_with_stdio(0); //cin.tie(0); //freopen("test_input.txt", "r", stdin); //freopen("test_output.txt", "w", stdout); int n;cin>>n; vi a(n); REP(i,0,n)cin>>a[i]; map<int,queue<int>> b; REP(i,0,n)b[a[i]].push(i); int pos=0; vi ans; while(pos<n){ ans.PB(a[pos]); int k=a[pos]; while(!b[k].empty()&&b[k].front()<=pos)b[k].pop(); if(b[k].empty()){ pos++;continue; } int x=b[k].front(); REP(i,pos,x-1)ans.PB(k); pos=x; } for(auto u:ans)cout<<u<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...