Submission #1047458

# Submission time Handle Problem Language Result Execution time Memory
1047458 2024-08-07T13:19:52 Z sofijavelkovska Event Hopping (BOI22_events) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5;

int n;
int l[MAXN], r[MAXN];

bool rcompare(int x, int y)
{
    if (r[x]==r[y])
        return l[x]<l[y];

    return r[x]<r[y];
}

int main()
{
    int n, q;
    cin >> n >> q;
    int l[n], r[n];
    for (int i=0; i<n; i++)
        cin >> l[i] >> r[i];
    int sorted[n];
    for (int i=0; i<n; i++)
        sorted[i]=i;
    sort(sorted, sorted+n, rcompare);
    int group[n];
    int current=0;
    int ranked[n];
    for (int i=0; i<n; i++)
    {
        ranked[sorted[i]]=i;
        if (i==0 || l[sorted[i]]<=r[sorted[i-1]])
            group[sorted[i]]=current;
        else
        {
            current=current+1;
            group[sorted[i]]=current;
        }
    }
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        x=x-1;
        y=y-1;
        if (group[x]!=group[y])
        {
            cout << "impossible" << '\n';
            continue;
        }
        if (x==y)
        {
            cout << 0 << '\n';
            continue;
        }
        if (r[x]==r[y])
        {
            cout << 1 << '\n';
            continue;
        }
        cout << ranked[y]-ranked[x] << '\n';
    }

    return 0;
}#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5;

int n;
int l[MAXN], r[MAXN];

bool rcompare(int x, int y)
{
    if (r[x]==r[y])
        return l[x]<l[y];

    return r[x]<r[y];
}

int main()
{
    int n, q;
    cin >> n >> q;
    int l[n], r[n];
    for (int i=0; i<n; i++)
        cin >> l[i] >> r[i];
    int sorted[n];
    for (int i=0; i<n; i++)
        sorted[i]=i;
    sort(sorted, sorted+n, rcompare);
    int group[n];
    int current=0;
    int ranked[n];
    for (int i=0; i<n; i++)
    {
        ranked[sorted[i]]=i;
        if (i==0 || l[sorted[i]]<=r[sorted[i-1]])
            group[sorted[i]]=current;
        else
        {
            current=current+1;
            group[sorted[i]]=current;
        }
    }
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        x=x-1;
        y=y-1;
        if (group[x]!=group[y])
        {
            cout << "impossible" << '\n';
            continue;
        }
        if (x==y)
        {
            cout << 0 << '\n';
            continue;
        }
        if (r[x]==r[y])
        {
            cout << 1 << '\n';
            continue;
        }
        cout << ranked[y]-ranked[x] << '\n';
    }

    return 0;
}

Compilation message

events.cpp:67:2: error: stray '#' in program
   67 | }#include <bits/stdc++.h>
      |  ^
events.cpp:67:3: error: 'include' does not name a type
   67 | }#include <bits/stdc++.h>
      |   ^~~~~~~
events.cpp:70:11: error: redefinition of 'const int MAXN'
   70 | const int MAXN=1e5;
      |           ^~~~
events.cpp:4:11: note: 'const int MAXN' previously defined here
    4 | const int MAXN=1e5;
      |           ^~~~
events.cpp:72:5: error: redefinition of 'int n'
   72 | int n;
      |     ^
events.cpp:6:5: note: 'int n' previously declared here
    6 | int n;
      |     ^
events.cpp:73:5: error: redefinition of 'int l [100000]'
   73 | int l[MAXN], r[MAXN];
      |     ^
events.cpp:7:5: note: 'int l [100000]' previously declared here
    7 | int l[MAXN], r[MAXN];
      |     ^
events.cpp:73:14: error: redefinition of 'int r [100000]'
   73 | int l[MAXN], r[MAXN];
      |              ^
events.cpp:7:14: note: 'int r [100000]' previously declared here
    7 | int l[MAXN], r[MAXN];
      |              ^
events.cpp:75:6: error: redefinition of 'bool rcompare(int, int)'
   75 | bool rcompare(int x, int y)
      |      ^~~~~~~~
events.cpp:9:6: note: 'bool rcompare(int, int)' previously defined here
    9 | bool rcompare(int x, int y)
      |      ^~~~~~~~
events.cpp:83:5: error: redefinition of 'int main()'
   83 | int main()
      |     ^~~~
events.cpp:17:5: note: 'int main()' previously defined here
   17 | int main()
      |     ^~~~