Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <algorithm>
- #define pb push_back
- using namespace std;
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int n;
- cin >> n;
- vector<int> m;
- m.reserve(n);
- for(int i = 0; i < n; i ++){
- int inp;
- cin >> inp;
- m.pb(inp);
- }
- map<int,int> cnt;
- for(int i = 0; i < n; i ++){
- if(cnt.count(m[i]) == 0){
- cnt[m[i]] = 1;
- }
- else{
- cnt[m[i]] += 1;
- }
- }
- map<int,int> first;
- map<int,int> last;
- vector<int> ind;
- for(int i = n-1; i > -1; i --){
- if(first.count(m[i]) == 0){
- first[m[i]] = i;
- ind.pb(m[i]);
- }
- }
- for(int i = n-1; i > -1; i --){
- if(last.count(m[i]) == 0){
- last[m[i]] = i;
- }
- }
- sort(ind.begin(),ind.end());
- vector<vector<int>> dp;
- if (first[ind[0]] == last[ind[0]]){
- dp.pb({1+first[ind[0]],99999999});
- }
- else{
- dp.pb({99999999,last[ind[0]]+cnt[ind[0]]})
- }
- for(int i = 1; i < ind.size()); i++){
- if(first[ind[i]] == last[ind[i]]){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement