47832023-03-31 12:18:56EyusieLeghosszabb béke (75 pont)cpp17Time limit exceeded 71/75203ms4116 KiB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100000

int n, k, m, l, mx, counter, indmx, indcur;

bool a[MAXN + 1];
int i;
int j = 1;

inline void fastscan(int &number)
{
    //variable to indicate sign of input number
    register int c;

    number = 0;

    // extract current character from buffer
    c = getchar();

    // Keep on extracting characters if they are integers
    // i.e ASCII Value lies from '0'(48) to '9' (57)
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
}

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);

    register bool x, ag1, ag2, neg_x;

    fastscan(n);
    fastscan(k);
    for(; i < k; ++i)
    {
        fastscan(m);
        fastscan(l);
        fill(a+m, a+l+1,1);
    }
    for(; j <= n; ++j)
    {
        /*
        if(a[j])
        {
            if(mx < counter)
            {
                indmx = indcur;
                mx = counter;
            }
            counter = 0;
        }
        else
        {
            if(counter == 0)
            {
                indcur = j;
                counter++;
            }
            else counter++;
        }*/

        ag1 = a[j];
        ag2 = !ag1;

        x = ag2*(counter == 0) + ag1*(mx < counter);
        neg_x = !x;
        indmx = ag2*indmx + ag1*(indmx*neg_x + indcur*x);
        mx = ag2*mx + ag1*(mx*neg_x + counter*x);
        indcur = ag2*(indcur*neg_x + j*x) + ag1*indcur;
        counter = ag2*(counter+1);

        //cout << ag1 << " " << ag2 << "\n";
        //cout << x << " " << indmx << " " << mx << " " << indcur << " " << counter << "\n";


    }

    if(mx < counter)
    {
        mx = counter;
        indmx = indcur;
    }


    if(mx == 0)
    {
        cout << "-1";
    }
    else cout << mx << " " << indmx;
}
SubtaskSumTestVerdictTimeMemory
base71/75
1Accepted0/03ms1904 KiB
2Accepted0/019ms2328 KiB
3Accepted3/33ms2176 KiB
4Accepted3/33ms2308 KiB
5Accepted3/32ms2520 KiB
6Accepted3/33ms3004 KiB
7Accepted3/33ms3004 KiB
8Accepted4/42ms2964 KiB
9Accepted4/43ms3096 KiB
10Accepted4/43ms3180 KiB
11Accepted4/43ms3184 KiB
12Accepted4/44ms3512 KiB
13Accepted4/43ms3724 KiB
14Accepted4/43ms3828 KiB
15Accepted4/44ms3788 KiB
16Accepted4/44ms3804 KiB
17Accepted4/44ms3704 KiB
18Accepted4/49ms3708 KiB
19Accepted4/428ms4008 KiB
20Accepted4/4146ms3960 KiB
21Time limit exceeded0/4203ms4116 KiB
22Accepted4/4148ms3960 KiB