Submission #139531

#TimeUsernameProblemLanguageResultExecution timeMemory
139531jovan_bStrange Device (APIO19_strange_device)C++17
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; vector <pair <ll, ll>> vec; int main(){ ios_base::sync_with_stdio(false); cout.precision(10); cout<<fixed; int n; cin >> n; ll a, b; cin >> a >> b; a /= __gcd(a, b+1); if(a <= 2000000000000000000LL/b) a *= b; cout << a << endl; while(n--){ ll l, r; cin >> l >> r; if(r-l+1 >= a){ cout << a << "\n"; return 0; } l %= a; r %= a; if(l > r){ vec.push_back({0, 1}); vec.push_back({r+1, -1}); vec.push_back({l, 1}); vec.push_back({a, -1}); } else{ vec.push_back({l, 1}); vec.push_back({r+1, -1}); } } sort(vec.begin(), vec.end()); n = vec.size(); ll res = 0; ll tren = 0; for(int i=0; i<n; i++){ ll val = vec[i].first; //cout << vec[i].first << " " << vec[i].second << endl; if(i > 0) val -= vec[i-1].first; if(tren) res += val; tren += vec[i].second; //cout << res << endl; } cout << res; return 0; }
#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...