Submission #782038

# Submission time Handle Problem Language Result Execution time Memory
782038 2023-07-13T14:59:49 Z VadimK Event Hopping (BOI22_events) C++17
0 / 100
265 ms 6056 KB
#include <bits/stdc++.h>
using namespace std;
struct event
{
    int s;
    int f;
    int num;
};
bool cmp (event a, event b)
{
    if (a.f==b.f) return a.s<=b.s;
    return a.f<b.f;
}
int main() {
    int n,q;
    cin>>n>>q;
    event arr[n+1];
    int p[n+1];
    for (int i=1; i<=n; i++)
        cin>>arr[i].s>>arr[i].f;
     for (int i=1; i<=n; i++)
        arr[i].num=i;
    sort (arr+1,arr+n+1,cmp);
     for (int i=1; i<=n; i++)
        p[arr[i].num]=i;
    int ori=1,start[n+1];
    start[1]=1;
     for (int i=1; i<n; i++)
        {
            if (arr[i+1].s<=arr[i].f&&arr[i].f<=arr[i+1].f) start[i+1]=ori;
            else {ori=i+1; start[i+1]=ori;}
        }
    while (q--)
    {
        int a,b;
        cin>>a>>b;
        a=p[a]; b=p[b];
        if (start[a]==start[b]&&a<=b) cout<<abs(a-b);
        else cout<<"impossible";
        cout<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 225 ms 2824 KB Output is correct
2 Correct 265 ms 2736 KB Output is correct
3 Correct 229 ms 2752 KB Output is correct
4 Correct 226 ms 3336 KB Output is correct
5 Correct 237 ms 3128 KB Output is correct
6 Incorrect 229 ms 6056 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -