28652023-01-31 09:37:36zsebiSíkság (55)cpp11Forditási hiba
// siksag.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <map>
#define ll long long 
using namespace std;
ll n, a,k;
deque<ll>v;
map<ll, ll>x;
ll melyik(ll a)
{
    if (abs(v[0] - a) == 1)return 1;
    else return 2;
}
ll has(ll a, ll b)
{
    if (x[a] < x[b])return 1;
    else return 2;
}
ll masik(ll a)
{
    if (abs(a- v[0])<=1)return 2;
    else return 1;
}
int main()
{

    cin >> n;
    ll maxi = 0,p;

  
    for (int i = 1; i <= n; ++i)
    {   
        cin >> a;
        x[a] = i;
        if (v.empty())
        {
            v.push_back(a);
            k = i;
        }
        else if (v.size() == 1)
        {
            if(abs(a - v[0]) == 1)
            v.push_back(a);
            else if(a!=v[0])
            {
                v[0] = i;
                k = i;
            }
        }
        else if (v.size()==2 && !count(v.begin(), v.end(), a))
        {
            if (abs(v[0] - a) != 1 && abs(v[1] - a) != 1)
            {
                v.clear();
                v.push_back(a);
                k = i;
            }
            else  if (has(v[0], v[1]) != melyik(a))
            {
                k = x[v[has(v[0], v[1])-1]] + 1;
                v[masik(a)-1] = a;
            }
            else
            {
                v.clear();
                v.push_back(a);
                k = i;
            }
        }
        if (i - k+1> maxi)
        {
            maxi = i - k+ 1;
            p = k;
        }

    }
    cout << maxi << " " << p;
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Forditási hiba
exit status 1
main.cpp: In function 'int main()':
main.cpp:53:34: error: 'count' was not declared in this scope
   53 |         else if (v.size()==2 && !count(v.begin(), v.end(), a))
      |                                  ^~~~~
Exited with error status 1