제출 #1011929

#제출 시각아이디문제언어결과실행 시간메모리
1011929UnforgettableplEvent Hopping 2 (JOI21_event2)C++17
100 / 100
157 ms43684 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,k; cin >> n >> k; vector<int> sortedidx(n); map<pair<int,int>,int> actidx; vector<pair<int,int>> ranges(n); for(auto&[a,b]:ranges)cin>>b>>a; vector<pair<pair<int,int>,int>> sorter; for(int i=0;i<n;i++)sorter.emplace_back(ranges[i],i); sort(sorter.begin(),sorter.end()); for(int i=0;i<n;i++)ranges[i]=sorter[i].first; for(int i=0;i<n;i++)sortedidx[sorter[i].second]=i; for(auto&[a,b]:ranges)swap(a,b); vector<vector<int>> lift(n+2,vector<int>(17)); set<pair<int,int>> curr; curr.insert({1e10,n}); lift[n][0]=n; lift[n+1][0]=0; for(int i=n-1;i>=0;i--){ lift[i][0] = curr.lower_bound({ranges[i].second,0ll})->second; while(curr.begin()->first<=ranges[i].first)curr.erase(curr.begin()); curr.insert({ranges[i].first,i}); } ranges.emplace_back(1e10,1e10+1); ranges.emplace_back(-1,0); for(int bit=1;bit<=16;bit++){ for(int i=0;i<=n+1;i++){ lift[i][bit] = lift[lift[i][bit-1]][bit-1]; } } auto get = [&](int x,int r){ int ans = 0; for(int jump=16;jump>=0;jump--){ if(ranges[lift[x][jump]].second<=r){ x = lift[x][jump]; ans+=1<<jump; } } return ans; }; if(get(n+1,1e9)<k){ cout << "-1\n"; return 0; } vector<int> ans; int currsum = get(n+1,1e9); set<tuple<int,bool,int>> points; // True is left, false is right points.insert({0,false,n+1}); points.insert({1e10,true,n}); for(int i=0;i<n;i++){ int idx = sortedidx[i]; auto [r,type,rx] = *points.upper_bound({ranges[idx].first,false,n+3}); if(type==false)continue; if(r<ranges[idx].second)continue; auto [l,t,lx] = *(--points.upper_bound({ranges[idx].first,false,n+3})); int delta = -get(lx,r)+1+get(lx,ranges[idx].first)+get(idx,r); if(currsum+delta>=k){ currsum+=delta; ans.emplace_back(i); points.insert({ranges[idx].first,true,idx}); points.insert({ranges[idx].second,false,idx}); if(ans.size()==k)break; } } for(int&i:ans)cout<<++i<<'\n'; }

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

event2.cpp: In function 'int32_t main()':
event2.cpp:70:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   70 |             if(ans.size()==k)break;
      |                ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...