Submission #723177

#TimeUsernameProblemLanguageResultExecution timeMemory
723177culver0412Strange Device (APIO19_strange_device)C++17
35 / 100
1329 ms28820 KiB
#include<bits/stdc++.h> using namespace std; int main(){ long long int n,a,b; cin >> n >> a >> b; long long int x=a/gcd(a,b+1)*b; vector<pair<long long int,long long int>> ranges; for(int i=0;i<n;i++){ long long int l,r; cin >> l >> r; if(r-l+1>=x){ cout << x << endl; return 0; } l%=x; r%=x; if(l<=r){ ranges.push_back({l,r}); } else{ ranges.push_back({0,r}); ranges.push_back({l,x-1}); } } sort(ranges.begin(),ranges.end()); long long int curl=ranges[0].first,curr=ranges[0].second,ans=0; for(int i=1;i<ranges.size();i++){ pair<long long int,long long int> range=ranges[i]; if(curr<range.first){ ans+=(curr-curl+1); curl=range.first; curr=range.second; } else{ curr=max(curr,range.second); } } ans+=(curr-curl+1); cout << ans << endl; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=1;i<ranges.size();i++){
      |                 ~^~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...