Submission #997846

#TimeUsernameProblemLanguageResultExecution timeMemory
997846faqinyeagerStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
210 ms27048 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<int> t; int F(vector<int>& a, int val){ int l = 0, r = a.size() - 1, best = -1; while(l <= r){ int mid = (l + r) / 2; if(a[mid] >= val){ best = mid; r = mid - 1; }else{ l = mid + 1; } } return a[best]; } int main(){ cin >> n; t.resize(n); map<int, vector<int>> tmp; for(int i = 0; i < n; i++){ cin >> t[i]; tmp[t[i]].push_back(i); } int ind = 0, val; while(ind < n){ val = t[ind]; vector<int> a = tmp[val]; int start = F(a, ind); int end = a.back(); //cout << start << ' ' << end << "; val - " << val << '\n'; for(int i = start; i <= end; i++) cout << val << '\n'; ind = end + 1; } } // 1 2 3 1 3 2 3 4 1 2 3 5 5 4 // 1 1 1 1 1 1 1 1 1 2 3 5 5 4
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...