Submission #1111542

# Submission time Handle Problem Language Result Execution time Memory
1111542 2024-11-12T09:24:38 Z gelastropod Fire (BOI24_fire) C++14
0 / 100
597 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;

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

void upd(int n, int x, int i)
{
    while (n <= M)
    {
        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 N, a, b;
    cin >> N >> M;
    tree = vector<pair<int, int>>(M + 1, {-1, -1});
    set<pair<int, int>> pairss;
    vector<pair<int, int>> pairs;
    for (int i = 0; i < N; i++)
    {
        cin >> a >> b;
        a++, b++;
        if (a > b) b += M;
        pairss.insert({a, b});
    }
    int counter = 0;
    while (!pairss.empty())
    {
        pairs.push_back(*pairss.begin());
        upd(pairss.begin()->first, pairss.begin()->second, counter);
        counter++;
        pairss.erase(pairss.begin());
    }
    int anss = INT_MAX;
    for (int i = 0; i < pairs.size(); i++)
    {
        int num = 1;
        int ca = pairs[i].first, cb = pairs[i].second;
        int prev = i;
        while (cb - ca < M)
        {
            auto z = qry(min(cb, M));
            if (z.first != -1 && z.second != prev && z.second != -1)
            {
                cb = max(cb, z.first);
                ca = min(ca, 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:52: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]
   52 |     for (int i = 0; i < pairs.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory 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 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 Runtime error 597 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 Runtime error 597 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 Runtime error 597 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Runtime error 526 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 3 ms 8072 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Runtime error 566 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 Runtime error 597 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -