235992026-01-26 08:28:49pirosmacska10Leghosszabb béke (75 pont)cpp17Időlimit túllépés 21/75300ms1012 KiB
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

using ll = long long;

vector<int> fen(100'001);

void add(int i, int num) {
    while (i != 0) {
        fen[i] += num;
        i -= i & -i;
    }
}

int ask(int i) {
    int res = 0;
    while (i > 0) {
        res += fen[i];
        i -= i & -i;
    }
    return res;
}
int subsequence(int a, int b) {
    return ask(b) - ask(a-1);
}

vector<bool> wars;

void binary(int a, int b) {
    if(a-b == 0) {
        add(a, 1);
        wars[a] = 1;
        return;
    }
    int summ = subsequence(a, b);
    if(summ == 0) {
        for(int i = a; i <= b; i++) {
            add(i, 1);
            wars[i] = 1;
        }
        return;
    }
    else if(a-b+1 != summ) {
        int half = (a+b+1)/2;
        binary(half, b);
        binary(a, half-1);
    } else return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    wars.resize(n+1);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        binary(a, b);
    }

    int maxx = 0;
    int first = -1;
    int run = 0;
    for(int i = 1; i <= n; i++) {
        if(wars[i]) {
            run = 0;
        } else {
            run++;
            if(maxx < run) {
                maxx = run;
                first = i-run+1;
            }
        }
    }
    if(first == -1) cout << "-1\n";
    else cout << maxx << " " << first;
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base21/75
1Elfogadva0/01ms820 KiB
2Időlimit túllépés0/0280ms820 KiB
3Elfogadva3/31ms820 KiB
4Hibás válasz0/31ms564 KiB
5Hibás válasz0/31ms820 KiB
6Elfogadva3/31ms820 KiB
7Elfogadva3/31ms820 KiB
8Elfogadva4/41ms612 KiB
9Elfogadva4/43ms568 KiB
10Elfogadva4/417ms820 KiB
11Időlimit túllépés0/4243ms820 KiB
12Időlimit túllépés0/4300ms820 KiB
13Időlimit túllépés0/4300ms824 KiB
14Időlimit túllépés0/4280ms824 KiB
15Időlimit túllépés0/4282ms1012 KiB
16Időlimit túllépés0/4282ms820 KiB
17Időlimit túllépés0/4300ms820 KiB
18Időlimit túllépés0/4289ms820 KiB
19Időlimit túllépés0/4293ms820 KiB
20Időlimit túllépés0/4282ms820 KiB
21Időlimit túllépés0/4300ms820 KiB
22Időlimit túllépés0/4293ms820 KiB