제출 #984295

#제출 시각아이디문제언어결과실행 시간메모리
984295TsaganaStrange Device (APIO19_strange_device)C++14
0 / 100
385 ms69920 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define int long long #define pi pair<int, int > #define pq priority_queue #define lb lower_bound #define ub upper_bound #define pb push_back #define eb emplace_back #define mset multiset #define F first #define S second using namespace std; int n, A, B, range; vector<pair<int, int>> v; int fastpow(int a, int b, int n) { if (!b) return 1; if (b % 2 == 0) {int r = fastpow(a, b / 2, n); return (r * r) % n;} else {int r = fastpow(a, b - 1, n); return (r * a) % n;} } int fastmul(int a, int b, int n) { if (b == 0) return 0; if (b % 2 == 0) {int r = fastmul(a, b / 2, n); return (r + r) % n;} else {int r = fastmul(a, b - 1, n); return (r + a) % n;} } int gcd(int a, int b) {return (!a ? b : gcd(b % a, a));} void build() { int L = gcd(B+1, A); range = fastmul(A / L, B, 1e18); } void calc(int l, int r) { if (r - l > range) {v.pb({1, range}); return ;} int s = l / range; l %= range ; r -= s * range; if (r > range) r -= range; v.pb({l, 1}); v.pb({r, 2}); } int count() { sort(all(v)); int ans = 0, se = 0, si = 0; for (auto i: v) { if (i.S & 1) { if (i.F > 0 && i.F <= se) ans += i.F - si + 1; } else { se = i.F; ans += i.F - si + 1; } si = i.F; } return ans; } void solve () { cin >> n >> A >> B; build(); for (int i = 1; i <= n; i++) { int l, r; cin >> l >> r; calc(l, r); } cout << count(); } signed main(){IOS solve(); 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...