Submission #659156

#TimeUsernameProblemLanguageResultExecution timeMemory
659156activedeltorreBridges (APIO19_bridges)C++14
0 / 100
100 ms55060 KiB
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; map<long long,long long>norm; vector<pair<long long,long long> >vec[2000005]; vector<pair<long long,long long > >complete; long long inf=1e18; bool cmp(pair<long long,long long> a,pair<long long,long long>b) { if(a.first!=b.first) { return a.first<b.first; } return a.second>b.second; } bool cmp2(pair<long long,long long> a,pair<long long,long long>b) { if(a.first!=b.first) { return a.first<b.first; } return a.second<b.second; } long long gcd(long long a , long long b) { if(b==0) return a; a%=b; return gcd(b,a); } int main() { long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z; cin>>n>>a>>b; a=a/gcd(a,b+1); for(i=1; i<=n; i++) { cin>>x>>y; val1=x/b; val2=y/b; rest1=x%b; rest2=y%b; if(val2-val1>=2) { val3=val1/a; val4=val2/a; if(val3==val4) { complete.push_back({(val1+1)%a,(val2-1)%a}); } else if(val4==val3+1) { complete.push_back({(val1+1)%a,a-1}); complete.push_back({0,(val2-1)%a}); } else { complete.push_back({0,a-1}); } } if(val1==val2) { valoare=(val1)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({rest1,rest2}); complete.push_back({valoare,inf}); } else { ///adaug preim segmnt valoare=(val1)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({rest1,b-1}); complete.push_back({valoare,inf}); ///adaug al doilea segmnt valoare=(val2)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({0,rest2}); complete.push_back({valoare,inf}); } } sort(complete.begin(),complete.end(),cmp2); long long suma=0,nr,dr,index,maxim=-1,index2,lft,rgh,st; for(z=0; z<complete.size(); z++) { lft=complete[z].first; rgh=complete[z].second; if(rgh==inf && (z==0 || complete[z-1].first!=lft)) { i=norm[lft]; sort(vec[i].begin(),vec[i].end(),cmp); nr=vec[i].size(); for(j=0; j<nr; j++) { index=j; st=vec[i][j].first; dr=vec[i][j].second; while(index+1<nr && dr>=vec[i][index+1].first) { dr=max(dr,vec[i][index+1].second); index++; } suma=suma+dr-st+1; j=index; } } else if(rgh!=inf) { index2=z; maxim=rgh; while(index2+1<complete.size() && maxim>=complete[index2+1].first) { if(complete[index2+1].second!=inf) { maxim=max(maxim,complete[index2+1].second); } index2++; } suma=suma+(maxim-lft+1)*(b); z=index2; } } cout<<suma; return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:98:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(z=0; z<complete.size(); z++)
      |              ~^~~~~~~~~~~~~~~~
bridges.cpp:125:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |             while(index2+1<complete.size() && maxim>=complete[index2+1].first)
      |                   ~~~~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:35:21: warning: unused variable 'm' [-Wunused-variable]
   35 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z;
      |                     ^
bridges.cpp:35:23: warning: unused variable 'k' [-Wunused-variable]
   35 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z;
      |                       ^
bridges.cpp:35:25: warning: unused variable 'l' [-Wunused-variable]
   35 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z;
      |                         ^
bridges.cpp:35:81: warning: unused variable 'rest3' [-Wunused-variable]
   35 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z;
      |                                                                                 ^~~~~
bridges.cpp:35:87: warning: unused variable 'rest4' [-Wunused-variable]
   35 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z;
      |                                                                                       ^~~~~
#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...