Submission #398444

#TimeUsernameProblemLanguageResultExecution timeMemory
398444AKikoStrange Device (APIO19_strange_device)C++17
5 / 100
1848 ms79604 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ss second #define ff first #define pb push_back #define pii pair<int, int> #define INF INT64_MAX #define debug(n) cout << #n << " = " << n << "\n"; #define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll MOD = 1e9 + 7; int main() { ll n, A, B, T, K; cin >> n >> A >> B; K = A / __gcd(B + 1, A); if(INF / A / B > 0) { T = K * B; } else { T = INF; } map<ll, ll> m; for(int i = 0; i < n; i++) { ll l, r; cin >> l >> r; if(r - l + 1 >= T) { cout << T << "\n"; return 0; } if(r % T < l % T) { m[0]++; m[r % T + 1]--; m[l]++; m[T]--; } else { m[l % T]++; m[r % T + 1]--; } } ll prev = 0; vector<pair<ll, ll> > segments; for(auto el : m) { prev += el.ss; segments.pb({el.ff, prev}); } ll ans = 0; for(int i = 0; i < int(segments.size() - 1); i++) { if(segments[i].ss > 0){ ans += segments[i + 1].ff - segments[i].ff; } } cout << ans << "\n"; /* (x, y) = ((t + t / B) % A, t % B) (x, y) = (((t + T) + (t + T) / B) % A, (t + T) % B); T = BK x = (t + t / B) % A x = ((t + T) + (t + T) / B) % A 0 = (BK + K) % A; 0 = K(B + 1) % A; */ return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#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...