Submission #916514

#TimeUsernameProblemLanguageResultExecution timeMemory
916514raypeng1729Stone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
147 ms28876 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; int a[n], id[n]; vector<int> v; for(int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for(int i = 0; i < n; i++) id[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); vector<vector<int>> pos(n); vector<int> to(n, -1); int cur = n, fin = 0; set<int> ext; for(int i = 0; i < n; i++) ext.insert(i); for(int i = 0; i < n; i++){ while(pos[id[i]].size() && !ext.count(pos[id[i]].back())) pos[id[i]].pop_back(); if(pos[id[i]].size()){ to[i] = pos[id[i]].back(); auto a = ext.lower_bound(to[i]); while(*a != i){ ext.erase(a); a = ext.lower_bound(to[i]); } } pos[id[i]].push_back(i); } for(int i = n - 1; i >= 0; i--){ if(to[i] == -1) continue; for(int j = i; j >= to[i]; j--) a[j] = a[i]; i = to[i] + 1; } for(int i = 0; i < n; i++) cout << a[i] << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:15:9: warning: unused variable 'cur' [-Wunused-variable]
   15 |     int cur = n, fin = 0;
      |         ^~~
Main.cpp:15:18: warning: unused variable 'fin' [-Wunused-variable]
   15 |     int cur = n, fin = 0;
      |                  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...