Submission #1112928

# Submission time Handle Problem Language Result Execution time Memory
1112928 2024-11-15T09:24:46 Z modwwe Event Hopping (BOI22_events) C++17
100 / 100
102 ms 36044 KB
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
//#define int  long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}
void phongbeo();
const int inf = 1e14;
const ll mod2 = 1e9 + 7;
const int  mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0)x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};
ll n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r,p ;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo();
    // checktime
}
ib minn[18][200001];
int st[17][100001];
ib a[100001];
vector<int> v;
ib mer(ib a,ib b)
{
    if(a.a<=b.a) return a;
    return b;
}
int getmin(int l,int r)
{
    int k=31-__builtin_clz(r-l+1);
    return mer(minn[k][l],minn[k][r-mask(k)+1]).b;
}
void phongbeo()
{
   n=scan();
   k=scan();
    for(int i=1; i<=n; i++)
        a[i].a=scan(),a[i].b=scan(),v.pb(a[i].b),v.pb(a[i].a);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    m=v.size();
    for(int i=1; i<=n; i++)
    {
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
        a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
    }
    for(int i=1; i<=m; i++)
        minn[0][i]= {m+1,i};
    for(int i=1; i<=n; i++)
    {
        if(a[i].a<=minn[0][a[i].b].a)
            minn[0][a[i].b]= {a[i].a,i};
    }
    for(int i=1; i<18; i++)
        for(int j=1; j+mask(i)-1<=m; j++)
            minn[i][j]=mer(minn[i-1][j],minn[i-1][j+mask(i-1)]);
    for(int i=1; i<=n; i++)
    {
        st[0][i]=getmin(a[i].a,a[i].b);
    }
    for(int i=1; i<17; i++)
        for(int j=1; j<=n; j++)
            st[i][j]=st[i-1][st[i-1][j]];
    while(k--)
    {
        down
      l=scan();
      r=scan();
        if(a[l].b>a[r].b)
        {
            cout<<"impossible";
            continue;
        }
        else if(l==r)
        {
            cout<<0;
            continue;
        }
        else if(a[l].b>=a[r].a&&a[r].b>=a[l].b)
        {
            cout<<1;
            continue;
        }
        else
        {
            s4=0;
            for(int i=16; i>=0; --i)
                if(a[st[i][r]].a>a[l].b)
                {
                    s4=s4+(1<<i);
                    r=st[i][r];
                }
            if(s4==131071)
            {
                cout<<"impossible";
                continue;
            }
            cout<<s4+2;
        }
    }
}

Compilation message

events.cpp:38:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+14' to '2147483647' [-Woverflow]
   38 | const int inf = 1e14;
      |                 ^~~~
events.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main()
      | ^~~~
events.cpp: In function 'void phongbeo()':
events.cpp:117:23: warning: narrowing conversion of '(m + 1)' from 'long long int' to 'int' [-Wnarrowing]
  117 |         minn[0][i]= {m+1,i};
      |                      ~^~
events.cpp:125:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  125 |             minn[i][j]=mer(minn[i-1][j],minn[i-1][j+mask(i-1)]);
      |                                                          ~^~
events.cpp:16:21: note: in definition of macro 'mask'
   16 | #define mask(k) (1<<k)
      |                     ^
events.cpp: In function 'int main()':
events.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
events.cpp:79:9: note: in expansion of macro 'fin'
   79 |         fin(task);
      |         ^~~
events.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".ans","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
events.cpp:80:9: note: in expansion of macro 'fou'
   80 |         fou(task);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 57 ms 21692 KB Output is correct
3 Correct 67 ms 23120 KB Output is correct
4 Correct 78 ms 21780 KB Output is correct
5 Correct 76 ms 23060 KB Output is correct
6 Correct 80 ms 24200 KB Output is correct
7 Correct 83 ms 24588 KB Output is correct
8 Correct 95 ms 36036 KB Output is correct
9 Correct 95 ms 36036 KB Output is correct
10 Correct 70 ms 23564 KB Output is correct
11 Correct 74 ms 28100 KB Output is correct
12 Correct 37 ms 23668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6648 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 1 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6648 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 1 ms 4856 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 4688 KB Output is correct
13 Correct 1 ms 4688 KB Output is correct
14 Correct 1 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 2 ms 4688 KB Output is correct
17 Correct 2 ms 4688 KB Output is correct
18 Correct 1 ms 4688 KB Output is correct
19 Correct 15 ms 5968 KB Output is correct
20 Correct 23 ms 5960 KB Output is correct
21 Correct 19 ms 6224 KB Output is correct
22 Correct 16 ms 6268 KB Output is correct
23 Correct 13 ms 6648 KB Output is correct
24 Correct 12 ms 6460 KB Output is correct
25 Correct 19 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6648 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 1 ms 4856 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 2 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 2 ms 4856 KB Output is correct
17 Correct 3 ms 4688 KB Output is correct
18 Correct 2 ms 4688 KB Output is correct
19 Correct 55 ms 21188 KB Output is correct
20 Correct 48 ms 21188 KB Output is correct
21 Correct 54 ms 21260 KB Output is correct
22 Correct 63 ms 25872 KB Output is correct
23 Correct 70 ms 34768 KB Output is correct
24 Correct 68 ms 34756 KB Output is correct
25 Correct 13 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 21772 KB Output is correct
2 Correct 73 ms 21700 KB Output is correct
3 Correct 82 ms 21776 KB Output is correct
4 Correct 102 ms 35856 KB Output is correct
5 Correct 71 ms 22220 KB Output is correct
6 Correct 101 ms 35524 KB Output is correct
7 Correct 84 ms 35612 KB Output is correct
8 Correct 76 ms 35856 KB Output is correct
9 Correct 60 ms 34828 KB Output is correct
10 Correct 79 ms 35268 KB Output is correct
11 Correct 74 ms 35012 KB Output is correct
12 Correct 80 ms 35188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 57 ms 21692 KB Output is correct
3 Correct 67 ms 23120 KB Output is correct
4 Correct 78 ms 21780 KB Output is correct
5 Correct 76 ms 23060 KB Output is correct
6 Correct 80 ms 24200 KB Output is correct
7 Correct 83 ms 24588 KB Output is correct
8 Correct 95 ms 36036 KB Output is correct
9 Correct 95 ms 36036 KB Output is correct
10 Correct 70 ms 23564 KB Output is correct
11 Correct 74 ms 28100 KB Output is correct
12 Correct 37 ms 23668 KB Output is correct
13 Correct 2 ms 6648 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 2 ms 4688 KB Output is correct
17 Correct 2 ms 4688 KB Output is correct
18 Correct 2 ms 4688 KB Output is correct
19 Correct 2 ms 4688 KB Output is correct
20 Correct 2 ms 4688 KB Output is correct
21 Correct 1 ms 4856 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 4688 KB Output is correct
25 Correct 1 ms 4688 KB Output is correct
26 Correct 1 ms 4688 KB Output is correct
27 Correct 2 ms 4688 KB Output is correct
28 Correct 2 ms 4688 KB Output is correct
29 Correct 2 ms 4688 KB Output is correct
30 Correct 1 ms 4688 KB Output is correct
31 Correct 15 ms 5968 KB Output is correct
32 Correct 23 ms 5960 KB Output is correct
33 Correct 19 ms 6224 KB Output is correct
34 Correct 16 ms 6268 KB Output is correct
35 Correct 13 ms 6648 KB Output is correct
36 Correct 12 ms 6460 KB Output is correct
37 Correct 19 ms 6224 KB Output is correct
38 Correct 2 ms 6480 KB Output is correct
39 Correct 2 ms 4432 KB Output is correct
40 Correct 2 ms 4688 KB Output is correct
41 Correct 2 ms 4688 KB Output is correct
42 Correct 2 ms 4688 KB Output is correct
43 Correct 2 ms 4688 KB Output is correct
44 Correct 2 ms 4856 KB Output is correct
45 Correct 3 ms 4688 KB Output is correct
46 Correct 2 ms 4688 KB Output is correct
47 Correct 55 ms 21188 KB Output is correct
48 Correct 48 ms 21188 KB Output is correct
49 Correct 54 ms 21260 KB Output is correct
50 Correct 63 ms 25872 KB Output is correct
51 Correct 70 ms 34768 KB Output is correct
52 Correct 68 ms 34756 KB Output is correct
53 Correct 13 ms 9676 KB Output is correct
54 Correct 64 ms 21772 KB Output is correct
55 Correct 73 ms 21700 KB Output is correct
56 Correct 82 ms 21776 KB Output is correct
57 Correct 102 ms 35856 KB Output is correct
58 Correct 71 ms 22220 KB Output is correct
59 Correct 101 ms 35524 KB Output is correct
60 Correct 84 ms 35612 KB Output is correct
61 Correct 76 ms 35856 KB Output is correct
62 Correct 60 ms 34828 KB Output is correct
63 Correct 79 ms 35268 KB Output is correct
64 Correct 74 ms 35012 KB Output is correct
65 Correct 80 ms 35188 KB Output is correct
66 Correct 1 ms 6480 KB Output is correct
67 Correct 60 ms 23052 KB Output is correct
68 Correct 69 ms 22972 KB Output is correct
69 Correct 82 ms 21700 KB Output is correct
70 Correct 76 ms 22980 KB Output is correct
71 Correct 76 ms 24272 KB Output is correct
72 Correct 77 ms 24788 KB Output is correct
73 Correct 93 ms 35856 KB Output is correct
74 Correct 100 ms 36044 KB Output is correct
75 Correct 76 ms 22212 KB Output is correct
76 Correct 80 ms 27332 KB Output is correct
77 Correct 37 ms 22212 KB Output is correct
78 Correct 1 ms 6480 KB Output is correct
79 Correct 2 ms 6736 KB Output is correct
80 Correct 2 ms 6736 KB Output is correct
81 Correct 1 ms 4688 KB Output is correct
82 Correct 2 ms 4688 KB Output is correct
83 Correct 2 ms 4688 KB Output is correct
84 Correct 2 ms 4688 KB Output is correct
85 Correct 1 ms 4688 KB Output is correct
86 Correct 15 ms 7964 KB Output is correct
87 Correct 17 ms 5912 KB Output is correct
88 Correct 18 ms 6224 KB Output is correct
89 Correct 16 ms 6224 KB Output is correct
90 Correct 12 ms 6492 KB Output is correct
91 Correct 10 ms 6480 KB Output is correct
92 Correct 20 ms 6224 KB Output is correct
93 Correct 49 ms 21188 KB Output is correct
94 Correct 47 ms 22556 KB Output is correct
95 Correct 52 ms 22552 KB Output is correct
96 Correct 58 ms 26836 KB Output is correct
97 Correct 61 ms 34836 KB Output is correct
98 Correct 61 ms 34756 KB Output is correct
99 Correct 14 ms 11724 KB Output is correct
100 Correct 85 ms 35580 KB Output is correct
101 Correct 83 ms 35524 KB Output is correct
102 Correct 84 ms 35780 KB Output is correct
103 Correct 86 ms 35272 KB Output is correct
104 Correct 78 ms 35092 KB Output is correct
105 Correct 84 ms 35340 KB Output is correct
106 Correct 66 ms 18884 KB Output is correct
107 Correct 85 ms 21956 KB Output is correct
108 Correct 66 ms 21956 KB Output is correct
109 Correct 67 ms 21956 KB Output is correct
110 Correct 90 ms 35524 KB Output is correct
111 Correct 78 ms 35524 KB Output is correct