Submission #159518

#TimeUsernameProblemLanguageResultExecution timeMemory
159518jhnah917Strange Device (APIO19_strange_device)C++14
100 / 100
882 ms69180 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef __int128 asdf; typedef pair<asdf, asdf> p; ll _n, _a, _b; asdf n, a, b, c, sz; void print(__int128 x){ string s; while(x){ s += (char)(x%10 + '0'); x /= 10; } reverse(s.begin(), s.end()); cout << s; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> _n >> _a >> _b; n = _n, a = _a, b = _b; sz = a / __gcd(a, b+1) * b; vector<p> v; for(int i=0; i<n; i++){ ll _l, _r; cin >> _l >> _r; asdf l, r; l = _l, r = _r; if(r-l+1 > sz){ print(sz); return 0; } l %= sz, r %= sz; if(l <= r) v.emplace_back(l, r); else v.emplace_back(l, sz-1), v.emplace_back(0, r); } sort(v.begin(), v.end()); asdf ans = 0; for(int i=0; i<v.size(); i++){ int j = i; asdf now = v[i].second; while(j < v.size() && v[j].first <= now){ now = max(now, v[j].second); j++; } ans += now - v[i].first + 1; i = j - 1; } print(ans); }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
strange_device.cpp:41:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(j < v.size() && v[j].first <= now){
         ~~^~~~~~~~~~
#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...