Submission #1035193

#TimeUsernameProblemLanguageResultExecution timeMemory
1035193Halym2007Strange Device (APIO19_strange_device)C++17
35 / 100
341 ms67876 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define sz size() #define pii pair <ll, ll> const int N = 1e7 + 5; #define ll long long #define pb push_back vector <pii> v; ll n, a, b, l[N], r[N]; int main () { // freopen ("input.txt", "r", stdin); ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> a >> b; __int128 m = a / __gcd (a, b + 1) * b; for (int i = 1; i <= n; ++i) { cin >> l[i] >> r[i]; } // if (r[n] < m) { // ll jog = 0; // for (int i = 1; i <= n; ++i) { // jog += r[i] - l[i] + 1; // } // cout << jog; // return 0; // } for (int i = 1; i <= n; ++i) { if (r[i] - l[i] + 1 >= m) { // return cout << (ll)m, 0; v.pb ({0, m - 1}); continue; } if (l[i] % m > r[i] % m) { v.pb ({l[i] % m, m - 1}); v.pb ({0, r[i] % m}); } else { v.pb ({l[i] % m, r[i] % m}); } } sort (v.begin(), v.end()); // for (auto i : v) { // cout << i.ff << " " << i.ss << "\n"; // } // return 0; ll l1 = v[0].ff, r1 = v[0].ss, jogap = 0; for (int i = 1; i < (int)v.sz; ++i) { if (v[i].ff <= r1) r1 = max (r1, v[i].ss); else if (v[i].ff > r1) { jogap += r1 - l1 + 1; l1 = v[i].ff; r1 = v[i].ss; } } jogap += r1 - l1 + 1; cout << jogap; }
#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...