Submission #673820

#TimeUsernameProblemLanguageResultExecution timeMemory
673820QwertyPiStrange Device (APIO19_strange_device)C++14
100 / 100
1671 ms100376 KiB
#include <bits/stdc++.h> #define int long long using namespace std; ostream& operator<<(ostream& out, __int128_t x){ string s; while(x) s.push_back(x % 10 + '0'), x /= 10; reverse(s.begin(), s.end()); return out << s; } int32_t main(){ int n, a, b; cin >> n >> a >> b; __int128_t c = (__int128_t) b * (a / __gcd(a, b + 1)); vector<pair<__int128_t, __int128_t>> d; for(int i = 0; i < n; i++){ int l, r; cin >> l >> r; if(r - l + 1 >= c){ cout << c << endl; return 0; } if(l / c == r / c){ d.push_back({l % c, 1}); d.push_back({r % c + 1, -1}); }else{ d.push_back({l % c, 1}); d.push_back({0, 1}); d.push_back({r % c + 1, -1}); } } d.push_back({c, 0}); sort(d.begin(), d.end()); int cnt = 0, ans = 0; for(int i = 0; i < d.size() - 1; i++){ cnt += d[i].second; if(cnt > 0){ ans += d[i + 1].first - d[i].first; } } cout << ans << endl; }

Compilation message (stderr)

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:32:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<__int128, __int128> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < d.size() - 1; 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...