245952026-02-12 21:57:47pirosmacska10Síkság (55)cpp17Wrong answer 49/5512ms1612 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>
#include <cmath>
#include <queue>

using namespace std;
using ll=long long;

const ll INF=LLONG_MAX;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> nums(n);
    for(int i = 0; i < n; i++) {
        cin >> nums[i];
    }   


    int bottom = nums[0];
    int l = 0;
    vector<int> cnt(100'001, 0);
    vector<int> last(100'001, -1);
    int maxx = 0;
    int max_start = 0;
    for(int r = 1; r < n; r++) {
        cnt[nums[r]]++;
        last[nums[r]] = r;
        if(nums[r] < bottom) {
            while (l <= last[bottom+1]) {
                cnt[nums[l++]]--;
            }
            if(nums[r] < bottom-1) {
                while (l <= last[bottom]) {
                    cnt[nums[l++]]--;
                }
            }
            bottom = nums[r];
        }
        else if(nums[r] > bottom+1) {
            while (l <= last[bottom]) {
                cnt[nums[l++]]--;
            }
            if(nums[r] > bottom+2) {
                while (l <= last[bottom+1]) {
                    cnt[nums[l++]]--;
                }
            }
            bottom = nums[r]-1;
        }
        if(r-l+1 > maxx) {
            maxx = r-l+1;
            max_start = l;
        }
    }
    cout << maxx << " " << max_start+1;
}
SubtaskSumTestVerdictTimeMemory
base49/55
1Accepted0/02ms1076 KiB
2Accepted0/03ms1076 KiB
3Wrong answer0/22ms1260 KiB
4Wrong answer0/22ms1076 KiB
5Wrong answer0/22ms1008 KiB
6Accepted2/22ms1148 KiB
7Accepted3/32ms1076 KiB
8Accepted2/22ms1100 KiB
9Accepted3/32ms1076 KiB
10Accepted3/33ms1076 KiB
11Accepted3/32ms1104 KiB
12Accepted3/32ms1076 KiB
13Accepted3/312ms1596 KiB
14Accepted3/38ms1432 KiB
15Accepted3/39ms1588 KiB
16Accepted3/312ms1588 KiB
17Accepted3/312ms1588 KiB
18Accepted3/312ms1612 KiB
19Accepted3/312ms1588 KiB
20Accepted3/312ms1588 KiB
21Accepted3/37ms1332 KiB
22Accepted3/38ms1508 KiB