제출 #1061711

#제출 시각아이디문제언어결과실행 시간메모리
1061711new_accEscape Route 2 (JOI24_escape2)C++14
100 / 100
2193 ms111560 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e5+10; const int INFi=2e9; const ll INFl=1e16; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=2027865967; const ll p=70032301; const ull p2=913; const int L=17; int n,m; vector<pair<int,int>> t[N]; vi t2[N],naj[N][L]; pair<int,ll> jp[N][L]; pair<int,int> num[N]; map<pair<int,int>, ll> mm; ll zn(int a,int b,int ost){ ll curr=0; b--; for(int i=ost;i>=0;i--){ if(num[jp[a][i].fi].fi<=b){ curr+=jp[a][i].se; a=jp[a][i].fi; } } curr+=t[b][num[a].se].se-t[b][num[a].se].fi; return curr; } void solve(){ cin>>n>>m; vector<pair<int,int>> cr; int li=0; for(int i=1;i<n;i++){ int a; cin>>a; while(a--){ int x,d; cin>>x>>d; cr.push_back({x,d}); } sort(cr.begin(),cr.end()); reverse(cr.begin(),cr.end()); while(cr.size()){ while(t[i].size() and t[i].back().se>=cr.back().se) t[i].pop_back(); t[i].push_back(cr.back()); cr.pop_back(); } for(int i2=0;i2<t[i].size();i2++){ t2[i].push_back(++li); num[li]={i,i2}; } } num[li+1].fi=n; for(int i=0;i<L;i++) jp[li+1][i].fi=li+1; for(int i=1;i<n;i++){ int curr=0; for(int i2=0;i2<t[i].size();i2++){ while(curr<t[i+1].size() and t[i+1][curr].fi<t[i][i2].se) curr++; ll xd=t[i][i2].se-t[i][i2].fi; if(curr==t[i+1].size()){ if(i<n-1) xd+=m-t[i][i2].se+t[i+1][0].fi,jp[t2[i][i2]][0].fi=t2[i+1][0]; else jp[t2[i][i2]][0].fi=li+1; }else{ xd+=t[i+1][curr].fi-t[i][i2].se; jp[t2[i][i2]][0].fi=t2[i+1][curr]; } jp[t2[i][i2]][0].se=xd; } } for(int i2=1;i2<L;i2++){ for(int i=1;i<=li;i++){ int g=jp[i][i2].fi; jp[i][i2].se=jp[i][i2-1].se+jp[jp[i][i2-1].fi][i2-1].se; jp[i][i2].fi=jp[jp[i][i2-1].fi][i2-1].fi; } } vector<pair<int,pair<ll,int>>> pom; int q; cin>>q; for(int i=1;i<=q;i++){ int a,b; cin>>a>>b; if(mm.count(make_pair(a,b))>0){ cout<<mm[make_pair(a,b)]<<"\n"; continue; } ll res=INFl; int xd=b-a-1; if(xd==0){ for(int i2=0;i2<t2[a].size();i2++){ res=min(res,(ll)t[b-1][i2].se-(ll)t[b-1][i2].fi); } mm[make_pair(a,b)]=res; cout<<res<<"\n"; }else{ int ost=0; for(int i2=0;i2<L;i2++){ if((1<<i2)<=xd) ost=i2; } if(!naj[a][ost].size()){ pom.clear(); for(auto u:t2[a]) pom.push_back({jp[u][ost].fi,{jp[u][ost].se,u}}); sort(pom.begin(),pom.end()); for(int i3=0;i3<pom.size();i3++){ if(i3==0 or pom[i3-1].fi!=pom[i3].fi) naj[a][ost].push_back(pom[i3].se.se); } } for(auto u:naj[a][ost]) res=min(res,zn(u,b,ost)); mm[make_pair(a,b)]=res; cout<<res<<"\n"; } } } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }

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

Main.cpp: In function 'void solve()':
Main.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int i2=0;i2<t[i].size();i2++){
      |                      ~~^~~~~~~~~~~~
Main.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i2=0;i2<t[i].size();i2++){
      |                      ~~^~~~~~~~~~~~
Main.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             while(curr<t[i+1].size() and t[i+1][curr].fi<t[i][i2].se) curr++;
      |                   ~~~~^~~~~~~~~~~~~~
Main.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             if(curr==t[i+1].size()){
      |                ~~~~^~~~~~~~~~~~~~~
Main.cpp:80:17: warning: unused variable 'g' [-Wunused-variable]
   80 |             int g=jp[i][i2].fi;
      |                 ^
Main.cpp:98:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |             for(int i2=0;i2<t2[a].size();i2++){
      |                          ~~^~~~~~~~~~~~~
Main.cpp:112:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<long long int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |                 for(int i3=0;i3<pom.size();i3++){
      |                              ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...