Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <set>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> v(n);
- for(int &x : v) {
- cin >> x;
- }
- int i = 0, j = 0;
- int ret = 0;
- int subarray_length = 0;
- map<int, int> cnt;
- while(j < n) {
- if(cnt.find(v[j]) == cnt.end() or cnt[v[j]] == 0) {
- ++cnt[v[j]];
- ++subarray_length;
- ret = max(ret, subarray_length);
- ++j;
- }
- else {
- --subarray_length;
- --cnt[v[i]];
- ++i;
- }
- }
- cout << ret << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment