Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <fstream>
- #include <map>
- #include <stack>
- using namespace std;
- typedef long long ll;
- const int INF = 1e9;
- int main()
- {
- ios_base::sync_with_stdio(false);
- // ifstream cin("in.txt");
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- map<int, int> cnt;
- int L = 0, R = 0;
- int current_length = 0;
- int ans = 0;
- while(R < n) {
- if(cnt.find(v[R]) == cnt.end() or cnt[v[R]] == 0) {
- cnt[v[R]] += 1;
- current_length += 1;
- ans = max(ans, current_length);
- R += 1;
- }
- else {
- current_length -= 1;
- cnt[v[L]] -= 1;
- L += 1;
- }
- }
- cout << ans << endl;
- return 0;
- }
- /*
- mapa<int, int> m;
- 1 2 1 3 2 i7 4 2j
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement