제출 #815566

#제출 시각아이디문제언어결과실행 시간메모리
815566vjudge1Event Hopping 2 (JOI21_event2)C++17
100 / 100
289 ms60396 KiB
#include <bits/stdc++.h>



using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll  d[N] , a[N] = {}, dp[N] ,  b[N] , c[N] , sp[N][20];

ll get(int l ,int r){
    ll ans = 0 ;
    for(int i = 19; i >= 0; i--){
        if(sp[l][i] <= r && sp[l][i] >= l){
            l = sp[l][i];
            ans += (1 << i);
        }
    }
    return ans;
}

void solve(){
    ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>n>>k;
    set<ll>st1;
    map<int,int>mp;
    for(i = 1; i <= n; i++){
        cin>>a[i]>>b[i];
        st1.insert(a[i]);
        st1.insert(b[i]);
    }
    for(auto it : st1)
        mp[it] = ++s;
    for(i = 1; i <= n; i++)
        a[i] = mp[a[i]] ,b[i] = mp[b[i]];
    for(i = 1; i <= 2 * n + 2; i++)
        c[i] = 2 * n + 1;
    for(i = 1; i <= n; i++)
        c[a[i]] = min(c[a[i]], b[i]);
    for(i = 2 * n; i >= 1; i--){
        c[i] = min(c[i] ,c[i + 1]);
        sp[i][0] = c[i];
    }
    for(j = 1; j < 20; j++)
        for(i = 1; i <= 2 * n; i++)
            sp[i][j] = sp[sp[i][j - 1]][j - 1];
    if(get(1 , 2  * n) < k){
        cout<<-1<<"\n";
        return;
    }
    f = get(1 , 2 * n);
    set<pair<int,int>>st;
    st.insert({1 , 1});
    st.insert({2 * n , 2 * n});
    for(i = 1; i <= n; i++){
        if(st.size() - 2 == k)
            break;
        auto it = st.lower_bound({b[i] , 1});
        auto it1 = it;
        it--;
        if(a[i] < it->se)
            continue;
        x = f;
        x -= get(it->se , it1->fi);
        x += get(it->se , a[i]);
        x += 1;
        x += get(b[i] , it1->fi);
        if(x >= k){
            f = x;
            cout<<i<<"\n";
            st.insert({a[i] , b[i]});
        }
    }
}

int main(){
    /*
     TL;
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif
     */
int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

컴파일 시 표준 에러 (stderr) 메시지

event2.cpp: In function 'void solve()':
event2.cpp:71:26: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   71 |         if(st.size() - 2 == k)
      |            ~~~~~~~~~~~~~~^~~~
event2.cpp:38:8: warning: unused variable 'q' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
event2.cpp:38:20: warning: unused variable 'm' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                    ^
event2.cpp:38:26: warning: unused variable 'z' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
event2.cpp:38:41: warning: unused variable 'l' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                         ^
event2.cpp:38:45: warning: unused variable 'r' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                             ^
event2.cpp:38:57: warning: unused variable 'y' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                         ^
event2.cpp:38:61: warning: unused variable 'mn' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                             ^~
event2.cpp:38:74: warning: unused variable 'mx' [-Wunused-variable]
   38 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...