Submission #733007

#TimeUsernameProblemLanguageResultExecution timeMemory
733007boyliguanhanStrange Device (APIO19_strange_device)C++17
100 / 100
471 ms18640 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int len; bool merged[2000100]; struct range { int l, r; bool operator < (range against) { return l < against.l; } }; vector<range> ranges; int gcd(int a, int b) { if(!b) return a; return gcd(b, a%b); } signed main() { cin.sync_with_stdio(false); cin.tie(nullptr); int n, a, b; cin >> n >> a >> b; __int128_t temp = b; temp*=a/gcd(a, b+1); if(temp>1e18) len = 2e18; else len = temp; for(int i = 0; i < n; i++) { int l, r; cin >> l >> r; if(r-l+1 >= len) { cout << len << '\n'; return 0; } l%=len, r%=len; if(l > r) { ranges.push_back({l, len-1}); ranges.push_back({0, r}); } else { ranges.push_back({l, r}); } } sort(ranges.begin(), ranges.end()); for(int i = 1; i < ranges.size(); i++) { if(ranges[i].l <= ranges[i-1].r) ranges[i].l = ranges[i-1].l, merged[i-1] = 1, ranges[i].r = max(ranges[i].r, ranges[i-1].r); } int ans = 0; for(int i = 0; i < ranges.size(); i++) if(!merged[i]) ans+=ranges[i].r-ranges[i].l+1; cout << ans << '\n'; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:45:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 1; i < ranges.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~
strange_device.cpp:50:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; 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...