답안 #1111614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111614 2024-11-12T10:00:45 Z gelastropod Fire (BOI24_fire) C++14
40 / 100
2000 ms 37744 KB
#include<bits/stdc++.h>
using namespace std;

int KK;
vector<pair<int, int>> tree;

void upd(int n, int x, int i)
{
    while (n <= KK)
    {
        if (tree[n].first < x)
            tree[n] = {x, i};
        n += n & (-n);
    }
}

pair<int, int> qry(int a)
{
    pair<int, int> ans = {-1, -1};
    while (a > 0)
    {
        if (ans.first < tree[a].first)
            ans = tree[a];
        a -= a & (-a);
    }
    return ans;
}

signed main()
{
    int M, N, a, b;
    cin >> N >> M;
    set<pair<int, int>> pairss;
    set<int> eh;
    vector<pair<int, int>> pairs;
    vector<int> funny;
    map<int, int> efunny;
    funny.push_back(0);
    for (int i = 0; i < N; i++)
    {
        cin >> a >> b;
        if (a > b) b += M;
        eh.insert(a);
        eh.insert(b);
        pairss.insert({a, b});
    }
    tree = vector<pair<int, int>>(eh.size() + 1, {-1, -1});
    int asdaa = -10;
    KK = eh.size();
    while (!eh.empty())
    {
        int aaa = *eh.begin();
        efunny[aaa] = funny.size();
        funny.push_back(aaa);
        if (asdaa == -10) asdaa = aaa;
        eh.erase(eh.begin());
    }
    int counter = 0;
    while (!pairss.empty())
    {
        pairs.push_back({efunny[pairss.begin()->first], efunny[pairss.begin()->second]});
        upd(efunny[pairss.begin()->first], efunny[pairss.begin()->second], counter);
        counter++;
        pairss.erase(pairss.begin());
    }
    funny[1] = asdaa;
    int anss = INT_MAX;
    for (int i = 0; i < pairs.size(); i++)
    {
        int num = 1;
        int ca = funny[pairs[i].first], cb = funny[pairs[i].second];
        int prev = i;
        while (cb - ca < M)
        {
            auto z = qry(efunny[cb]);
            if (z.first != -1 && z.second != prev && z.second != -1)
            {
                cb = max(cb, funny[z.first]);
                ca = min(ca, funny[pairs[z.second].first]);
                num++;
            }
            else
                break;
            prev = z.second;
        }
        if (cb - ca >= M)
            anss = min(num, anss);
    }
    if (anss == INT_MAX)
        cout << "-1\n";
    else
       cout << anss << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i = 0; i < pairs.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 24 ms 1360 KB Output is correct
40 Correct 583 ms 1116 KB Output is correct
41 Correct 19 ms 1104 KB Output is correct
42 Correct 615 ms 1056 KB Output is correct
43 Correct 7 ms 848 KB Output is correct
44 Correct 606 ms 848 KB Output is correct
45 Correct 598 ms 1060 KB Output is correct
46 Correct 602 ms 848 KB Output is correct
47 Correct 14 ms 1104 KB Output is correct
48 Correct 18 ms 1368 KB Output is correct
49 Correct 244 ms 1528 KB Output is correct
50 Correct 140 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 476 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 18 ms 1308 KB Output is correct
16 Correct 614 ms 848 KB Output is correct
17 Correct 7 ms 848 KB Output is correct
18 Correct 623 ms 848 KB Output is correct
19 Correct 12 ms 1360 KB Output is correct
20 Correct 37 ms 508 KB Output is correct
21 Execution timed out 2062 ms 37744 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 19 ms 1104 KB Output is correct
13 Correct 626 ms 1056 KB Output is correct
14 Correct 139 ms 848 KB Output is correct
15 Correct 38 ms 336 KB Output is correct
16 Execution timed out 2054 ms 24936 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 24 ms 1360 KB Output is correct
40 Correct 583 ms 1116 KB Output is correct
41 Correct 19 ms 1104 KB Output is correct
42 Correct 615 ms 1056 KB Output is correct
43 Correct 7 ms 848 KB Output is correct
44 Correct 606 ms 848 KB Output is correct
45 Correct 598 ms 1060 KB Output is correct
46 Correct 602 ms 848 KB Output is correct
47 Correct 14 ms 1104 KB Output is correct
48 Correct 18 ms 1368 KB Output is correct
49 Correct 244 ms 1528 KB Output is correct
50 Correct 140 ms 848 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 508 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 2 ms 476 KB Output is correct
60 Correct 1 ms 336 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 18 ms 1308 KB Output is correct
66 Correct 614 ms 848 KB Output is correct
67 Correct 7 ms 848 KB Output is correct
68 Correct 623 ms 848 KB Output is correct
69 Correct 12 ms 1360 KB Output is correct
70 Correct 37 ms 508 KB Output is correct
71 Execution timed out 2062 ms 37744 KB Time limit exceeded
72 Halted 0 ms 0 KB -