제출 #937633

#제출 시각아이디문제언어결과실행 시간메모리
937633kccStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
76 ms8088 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define KCC ios::sync_with_stdio(0);cin.tie(0); long long a[1000000]; set<pair<int, int>> s; // 數字,位置 vector<int> ans; vector<pair<int, int>> v; int main() { KCC int n; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) v.pb({a[i], i}); sort(v.begin(), v.end()); //for(int i = 0; i < n; i++) cout << v[i].first << ' ' << v[i].second << "\n"; for(int i = 0; i < n; i++){ pair<int, int> x = {a[i], i}; auto it = upper_bound(v.begin(), v.end(), x) - v.begin(); if(v[it].first == a[i]){ for(int j = i; j <= v[it].second; j++) ans.pb(a[i]); ans.pop_back(); i = v[it].second - 1; } else ans.pb(a[i]); } for(auto w : ans) cout << w << "\n"; return 0; } //按照顏色排序,從位置編號小的開始找
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...