제출 #895456

#제출 시각아이디문제언어결과실행 시간메모리
8954568pete8Event Hopping 2 (JOI21_event2)C++17
100 / 100
199 ms67384 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<float.h> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") using namespace std; #define int long long #define double long double const int mod=998244353,mxn=2e5+5,lg=22,inf=1e18,minf=-1e18,Mxn=100000; int n,k,sz; struct info{int l,r,posl,posr,realid,id;}; bool cmp(info a,info b){ if(a.r==b.r)return a.l>b.l; return a.r<b.r; } vector<info>v; vector<int>compress; int up[mxn+10][lg+5],mn[mxn+10]; int jump(int at,int bound){ int cnt=0; for(int i=lg;i>=0;i--)if(up[at][i]!=-inf&&up[at][i]!=0&&up[at][i]<=bound)at=up[at][i],cnt+=(1ll<<i); return cnt; } int32_t main(){ fastio cin>>n>>k; for(int i=0;i<n;i++){ int a,b;cin>>a>>b; v.pb({a,b,-1,-1,i,i}); compress.pb(a); compress.pb(b); } sort(all(compress)); unique(all(compress)); for(auto &i:v){ i.l=lb(all(compress),i.l)-compress.begin(); i.r=lb(all(compress),i.r)-compress.begin(); } int cur=0; int sz=compress.size(); fill(mn,mn+compress.size()+5,inf); for(int i=0;i<n;i++)mn[v[i].l]=min(mn[v[i].l],v[i].r); for(int i=sz-2;i>=0;i--)mn[i]=min(mn[i],mn[i+1]); int curcnt=0,at=0; for(int i=0;i<sz;i++)up[i][0]=mn[i]; for(int j=1;j<=lg;j++)for(int i=0;i<sz;i++)if(up[i][j-1]!=inf&&up[i][j-1]!=0)up[i][j]=up[up[i][j-1]][j-1]; curcnt=jump(0,sz); vector<int>ans; set<pii>st; int add=0; for(int i=0;i<n;i++){ int l,r; bool intersect=false; auto it=st.lb({v[i].r,-1}); if(it==st.begin())l=0; else{ it--; if(it->f>v[i].l||it->s==-1)intersect=true; l=it->f; it++; } if(it!=st.end()){ r=it->f; if(it->s==1)intersect=true; } else r=sz; if(intersect)continue; add=jump(l,v[i].l)+jump(v[i].r,r)-jump(l,r); if(curcnt+add+1<k)continue; curcnt+=add+1; ans.pb(i+1); st.insert({v[i].r,1}); st.insert({v[i].l,-1}); if(ans.size()==k)break; } if(ans.size()<k)cout<<-1<<'\n'; else for(int i=0;i<k;i++)cout<<ans[i]<<"\n"; return 0; }

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

event2.cpp: In function 'int32_t main()':
event2.cpp:104:16: 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]
  104 |   if(ans.size()==k)break;
      |      ~~~~~~~~~~^~~
event2.cpp:106:15: 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]
  106 |  if(ans.size()<k)cout<<-1<<'\n';
      |     ~~~~~~~~~~^~
event2.cpp:67:6: warning: unused variable 'cur' [-Wunused-variable]
   67 |  int cur=0;
      |      ^~~
event2.cpp:72:15: warning: unused variable 'at' [-Wunused-variable]
   72 |  int curcnt=0,at=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...