Submission #907441

#TimeUsernameProblemLanguageResultExecution timeMemory
907441ItamarStrange Device (APIO19_strange_device)C++14
100 / 100
608 ms70488 KiB
//#include "tree_contest.h" #include <iostream> using namespace std; #include <vector> #define vi vector<int> #define ll long long //#define ll __int128 #include <algorithm> #include <set> #include <string> #include <bitset> #include <cmath> #include <math.h> #define pll pair<ll,ll> #define vll vector<ll> #define pi pair<int,int> #include <map> #include <queue> #define x first #define y second #define pd pair<double,double> ll gcd(ll a, ll b) { if (a > b)swap(a, b); if (a == 0)return b; return gcd(b % a, a); } int main() { ll n,a, b; cin >> n>>a >> b; ios_base::sync_with_stdio(false); cin.tie(NULL); ll m = (a / gcd(a, b + 1)) * b; vector<pll> seg; for (int i = 0; i < n; i++) { ll l, r; cin >> l >> r; if (2 + (l / m) <= (r / m)) { cout << m; return 0; } if (l / m < r / m) { seg.push_back({ l % m,1 }); seg.push_back({ m ,-1 }); //seg.push_back({ l % m,m-1 }); //seg.push_back({ 0,r % m }); seg.push_back({ 0,1 }); seg.push_back({ 1+(r % m),-1 }); } else { seg.push_back({ l % m,1 }); seg.push_back({ 1+(r % m),-1}); //seg.push_back({ l % m,r % m }); } } sort(seg.begin(), seg.end()); int sum = 0; ll ans = 0; seg.push_back({ m,0 }); for (int i = 0; i < seg.size(); i++) { if (sum) { ans += seg[i].first - seg[i - 1].first; } sum += seg[i].second; } cout << ans; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:58:23: 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]
   58 |     for (int i = 0; i < seg.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...