47902023-03-31 12:31:43EyusieLeghosszabb béke (75 pont)cpp17Time limit exceeded 71/75202ms3888 KiB
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define MAXN 100000

#ifdef JO
// no getchar_unlocked on Windows so just call getchar
inline int getchar_unlocked() { return getchar(); }
inline int putchar_unlocked(int c) { return putchar(c); }
#endif

int n, k, m, l, mx, counter, indmx, indcur;
bool x, ag1, ag2, neg_x;
bool a[MAXN + 1];
int i;
int j = 1;

inline void writeInt (int n)
{
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}  //store reverse of N in rev
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}

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_unlocked())
        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)
    {
        putchar_unlocked('-');
        putchar_unlocked('1');
        return 0;
    }

    writeInt(mx);
    putchar_unlocked(' ');
    writeInt(indmx);

}
SubtaskSumTestVerdictTimeMemory
base71/75
1Accepted0/03ms1884 KiB
2Accepted0/017ms2280 KiB
3Accepted3/33ms2284 KiB
4Accepted3/33ms2532 KiB
5Accepted3/33ms2740 KiB
6Accepted3/32ms2824 KiB
7Accepted3/33ms2820 KiB
8Accepted4/42ms2820 KiB
9Accepted4/43ms2940 KiB
10Accepted4/43ms2952 KiB
11Accepted4/43ms2944 KiB
12Accepted4/43ms2956 KiB
13Accepted4/43ms3168 KiB
14Accepted4/43ms3024 KiB
15Accepted4/43ms3028 KiB
16Accepted4/44ms3292 KiB
17Accepted4/44ms3256 KiB
18Accepted4/48ms3520 KiB
19Accepted4/425ms3888 KiB
20Accepted4/4148ms3840 KiB
21Time limit exceeded0/4202ms3840 KiB
22Accepted4/4145ms3856 KiB