제출 #1117096

#제출 시각아이디문제언어결과실행 시간메모리
1117096ttamxEvent Hopping 2 (JOI21_event2)C++17
39 / 100
217 ms20336 KiB
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; const int LG=17; int n,k; int l[N],r[N]; vector<int> ep; set<int> st,ed; vector<int> ans; struct Doubling{ int nxt[LG][N]; void set(int u,int v){ nxt[0][u]=v; } void build(){ for(int i=1;i<LG;i++){ for(int j=0;j<=n;j++){ nxt[i][j]=nxt[i-1][nxt[i-1][j]]; } } } template<class F> int query(int u,const F &f){ if(!f(u))return 0; int res=0; for(int i=LG-1;i>=0;i--){ int v=nxt[i][u]; if(f(v)){ u=v; res|=1<<i; } } return res+1; } }pre; int search(int x){ int lo=0,hi=ep.size()-1; while(lo<hi){ int m=(lo+hi+1)/2; if(x>=r[ep[m]])lo=m; else hi=m-1; } return ep[lo]; } int query(int x){ int cur=search(*st.lower_bound(x)); int lb=*prev(ed.upper_bound(x)); return pre.query(cur,[&](int u){return l[u]>=lb;}); } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> k; for(int i=1;i<=n;i++){ cin >> l[i] >> r[i]; } vector<int> ord(n); iota(ord.begin(),ord.end(),1); sort(ord.begin(),ord.end(),[&](int i,int j){ return r[i]<r[j]||(r[i]==r[j]&&l[i]>l[j]); }); ep.emplace_back(0); int idx=0; for(auto i:ord){ if(l[i]<=l[ep.back()]){ continue; } while(idx+1<ep.size()&&r[ep[idx+1]]<=l[i]){ idx++; } pre.set(i,ep[idx]); ep.emplace_back(i); } st.emplace(0); st.emplace(1e9); ed.emplace(1); ed.emplace(1e9+1); pre.build(); int base=query(1); if(base<k){ cout << -1; exit(0); } for(int i=1;i<=n;i++){ int pos=*ed.upper_bound(l[i]); if(pos<=r[i]||pos<*st.lower_bound(r[i])){ continue; } int memo=base; base-=query(l[i])-1; st.emplace(l[i]); ed.emplace(r[i]); base+=query(l[i]); base+=query(r[i]); if(base<k){ base=memo; st.erase(l[i]); ed.erase(r[i]); }else{ ans.emplace_back(i); if(ans.size()==k){ break; } } } assert(ans.size()==k); for(auto x:ans){ cout << x << "\n"; } }

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

event2.cpp: In function 'int main()':
event2.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         while(idx+1<ep.size()&&r[ep[idx+1]]<=l[i]){
      |               ~~~~~^~~~~~~~~~
event2.cpp:107:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |             if(ans.size()==k){
      |                ~~~~~~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from event2.cpp:1:
event2.cpp:112:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  112 |     assert(ans.size()==k);
      |            ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...