답안 #1112927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112927 2024-11-15T09:22:45 Z modwwe Event Hopping (BOI22_events) C++17
100 / 100
116 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()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b,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
        cin>>l>>r;
        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:116:23: warning: narrowing conversion of '(m + 1)' from 'long long int' to 'int' [-Wnarrowing]
  116 |         minn[0][i]= {m+1,i};
      |                      ~^~
events.cpp:124:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  124 |             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);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 80 ms 23160 KB Output is correct
3 Correct 92 ms 23060 KB Output is correct
4 Correct 95 ms 21772 KB Output is correct
5 Correct 100 ms 22976 KB Output is correct
6 Correct 99 ms 24272 KB Output is correct
7 Correct 100 ms 25880 KB Output is correct
8 Correct 116 ms 35856 KB Output is correct
9 Correct 112 ms 36044 KB Output is correct
10 Correct 97 ms 23492 KB Output is correct
11 Correct 97 ms 28180 KB Output is correct
12 Correct 50 ms 23500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 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 3 ms 4904 KB Output is correct
9 Correct 1 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 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 3 ms 4904 KB Output is correct
9 Correct 1 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 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 6736 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 4856 KB Output is correct
18 Correct 1 ms 4688 KB Output is correct
19 Correct 23 ms 6176 KB Output is correct
20 Correct 38 ms 5968 KB Output is correct
21 Correct 26 ms 6224 KB Output is correct
22 Correct 22 ms 6236 KB Output is correct
23 Correct 19 ms 6480 KB Output is correct
24 Correct 20 ms 6480 KB Output is correct
25 Correct 22 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 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 3 ms 4904 KB Output is correct
9 Correct 1 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 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 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 71 ms 21268 KB Output is correct
20 Correct 55 ms 21188 KB Output is correct
21 Correct 61 ms 21264 KB Output is correct
22 Correct 65 ms 25888 KB Output is correct
23 Correct 79 ms 34828 KB Output is correct
24 Correct 73 ms 34752 KB Output is correct
25 Correct 20 ms 11724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 21700 KB Output is correct
2 Correct 88 ms 23060 KB Output is correct
3 Correct 90 ms 22980 KB Output is correct
4 Correct 105 ms 36036 KB Output is correct
5 Correct 84 ms 23496 KB Output is correct
6 Correct 101 ms 35596 KB Output is correct
7 Correct 96 ms 35524 KB Output is correct
8 Correct 90 ms 35856 KB Output is correct
9 Correct 68 ms 34756 KB Output is correct
10 Correct 92 ms 35280 KB Output is correct
11 Correct 86 ms 35012 KB Output is correct
12 Correct 95 ms 35340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 80 ms 23160 KB Output is correct
3 Correct 92 ms 23060 KB Output is correct
4 Correct 95 ms 21772 KB Output is correct
5 Correct 100 ms 22976 KB Output is correct
6 Correct 99 ms 24272 KB Output is correct
7 Correct 100 ms 25880 KB Output is correct
8 Correct 116 ms 35856 KB Output is correct
9 Correct 112 ms 36044 KB Output is correct
10 Correct 97 ms 23492 KB Output is correct
11 Correct 97 ms 28180 KB Output is correct
12 Correct 50 ms 23500 KB Output is correct
13 Correct 2 ms 6480 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 3 ms 4904 KB Output is correct
21 Correct 1 ms 4688 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 2 ms 4688 KB Output is correct
25 Correct 2 ms 4688 KB Output is correct
26 Correct 2 ms 6736 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 4856 KB Output is correct
30 Correct 1 ms 4688 KB Output is correct
31 Correct 23 ms 6176 KB Output is correct
32 Correct 38 ms 5968 KB Output is correct
33 Correct 26 ms 6224 KB Output is correct
34 Correct 22 ms 6236 KB Output is correct
35 Correct 19 ms 6480 KB Output is correct
36 Correct 20 ms 6480 KB Output is correct
37 Correct 22 ms 8016 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 1 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 4688 KB Output is correct
45 Correct 2 ms 4688 KB Output is correct
46 Correct 2 ms 4688 KB Output is correct
47 Correct 71 ms 21268 KB Output is correct
48 Correct 55 ms 21188 KB Output is correct
49 Correct 61 ms 21264 KB Output is correct
50 Correct 65 ms 25888 KB Output is correct
51 Correct 79 ms 34828 KB Output is correct
52 Correct 73 ms 34752 KB Output is correct
53 Correct 20 ms 11724 KB Output is correct
54 Correct 78 ms 21700 KB Output is correct
55 Correct 88 ms 23060 KB Output is correct
56 Correct 90 ms 22980 KB Output is correct
57 Correct 105 ms 36036 KB Output is correct
58 Correct 84 ms 23496 KB Output is correct
59 Correct 101 ms 35596 KB Output is correct
60 Correct 96 ms 35524 KB Output is correct
61 Correct 90 ms 35856 KB Output is correct
62 Correct 68 ms 34756 KB Output is correct
63 Correct 92 ms 35280 KB Output is correct
64 Correct 86 ms 35012 KB Output is correct
65 Correct 95 ms 35340 KB Output is correct
66 Correct 2 ms 6480 KB Output is correct
67 Correct 78 ms 21704 KB Output is correct
68 Correct 84 ms 22980 KB Output is correct
69 Correct 102 ms 22976 KB Output is correct
70 Correct 98 ms 24332 KB Output is correct
71 Correct 96 ms 25456 KB Output is correct
72 Correct 99 ms 25796 KB Output is correct
73 Correct 106 ms 35852 KB Output is correct
74 Correct 111 ms 36036 KB Output is correct
75 Correct 97 ms 23568 KB Output is correct
76 Correct 90 ms 28100 KB Output is correct
77 Correct 54 ms 23492 KB Output is correct
78 Correct 2 ms 6480 KB Output is correct
79 Correct 2 ms 4688 KB Output is correct
80 Correct 2 ms 4688 KB Output is correct
81 Correct 2 ms 4688 KB Output is correct
82 Correct 1 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 22 ms 6012 KB Output is correct
87 Correct 24 ms 5976 KB Output is correct
88 Correct 26 ms 6196 KB Output is correct
89 Correct 24 ms 6248 KB Output is correct
90 Correct 20 ms 6480 KB Output is correct
91 Correct 19 ms 6480 KB Output is correct
92 Correct 20 ms 8016 KB Output is correct
93 Correct 65 ms 21188 KB Output is correct
94 Correct 54 ms 21188 KB Output is correct
95 Correct 58 ms 22468 KB Output is correct
96 Correct 66 ms 26820 KB Output is correct
97 Correct 72 ms 34764 KB Output is correct
98 Correct 72 ms 34764 KB Output is correct
99 Correct 18 ms 11724 KB Output is correct
100 Correct 106 ms 35524 KB Output is correct
101 Correct 104 ms 35524 KB Output is correct
102 Correct 100 ms 35860 KB Output is correct
103 Correct 100 ms 35268 KB Output is correct
104 Correct 92 ms 35092 KB Output is correct
105 Correct 98 ms 35268 KB Output is correct
106 Correct 87 ms 20164 KB Output is correct
107 Correct 94 ms 23236 KB Output is correct
108 Correct 84 ms 23240 KB Output is correct
109 Correct 80 ms 23236 KB Output is correct
110 Correct 88 ms 35592 KB Output is correct
111 Correct 96 ms 35604 KB Output is correct