Submission #240099

#TimeUsernameProblemLanguageResultExecution timeMemory
240099wiwihoStrange Device (APIO19_strange_device)C++14
100 / 100
904 ms45892 KiB
//#define NDEBUG #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define iceil(a, b) ((a + b - 1) / b) #define tomax(a, b) (a = max(a, b)) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} //#define TEST using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } int main(){ StarBurstStream int n; cin >> n; ll a, b; cin >> a >> b; ll x = a / __gcd(a, b + 1); ll t = x > iceil((1LL << 60), b) ? (1LL << 60) : x * b; vector<pll> e; for(int i = 0; i < n; i++){ ll l, r; cin >> l >> r; if(r - l + 1 >= t){ cout << t << "\n"; return 0; } if(l % t <= r % t){ e.eb(mp(l % t, 1)); e.eb(mp(r % t + 1, 0)); } else{ e.eb(mp(l % t, 1)); e.eb(mp(t, 0)); e.eb(mp(0, 1)); e.eb(mp(r % t + 1, 0)); } } // cerr << t << "\n"; ll ans = 0, lst = -1; int cnt = 0; lsort(e); for(pll i : e){ // cerr << i.F << " " << i.S << " " << lst << "\n"; if(i.S){ cnt++; if(lst == -1) lst = i.F; } else{ cnt--; if(cnt == 0){ // cerr << "test " << lst << " " << i.F << "\n"; ans += i.F - lst; lst = -1; } } // cerr << cnt << " " << ans << "\n"; } cout << ans << "\n"; 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...