Submission #397857

#TimeUsernameProblemLanguageResultExecution timeMemory
397857AnandStrange Device (APIO19_strange_device)C++14
100 / 100
1899 ms53408 KiB
#include<bits/stdc++.h> using namespace std; int main() { vector<pair<long long , long long>> v; long long n , a , b; cin >> n >> a >> b; long long s , f , ans = 0; a/=__gcd(a , b+1); if(a > 1e18/b) a = 1e18 + 1; else a = a * b; for(long long i = 0; i < n; i++) { long long l , r; cin >> l >> r; if(r - l + 1 >= a) v.push_back({0,a-1}); else if((r % a) < (l % a)) {v.push_back({l % a , a - 1}); v.push_back({0 , r % a});} else v.push_back({l % a , r % a}); } sort(v.begin(),v.end()); s = v[0].first , f = v[0].second; for(int i = 1; i < v.size(); i++) { if(v[i].first>f) ans += f - s + 1 , tie(s , f) = v[i]; else f = max(f,v[i].second); } cout << ans+f-s+1 << endl;; return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:32:22: 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]
   32 |     for(int i = 1; i < v.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...