Submission #1295424

#TimeUsernameProblemLanguageResultExecution timeMemory
1295424blackscreen1Strange Device (APIO19_strange_device)C++20
100 / 100
663 ms63060 KiB
#include <bits//stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; #define ll long long #define ld long double #define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1)) #define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1)) #define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1)) #define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1)) #define iloop_(m, h, g) for (auto i = m; i < h; i += g) #define jloop_(m, h, g) for (auto j = m; j < h; j += g) #define kloop_(m, h, g) for (auto k = m; k < h; k += g) #define lloop_(m, h, g) for (auto l = m; l < h; l += g) #define getchar_unlocked _getchar_nolock // comment before submission #define pll pair<ll, ll> #define plll pair<ll, pll> #define pllll pair<pll, pll> #define vll vector<ll> #define qll queue<ll> #define dll deque<ll> #define pqll priority_queue<ll> #define gll greater<ll> #define INF 1000000000000000 #define MOD1 1000000007 #define MOD2 998244353 #define MOD3 1000000009 mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); set<pll> st; void ins(pll v) { if (!st.size()) {st.insert(v); return;} auto it = st.upper_bound(v); if (it != st.begin()) { it--; if ((*it).second >= v.first) { v.first = min(v.first, (*it).first); v.second = max(v.second, (*it).second); auto it2 = it++; st.erase(it2); } else it++; } while (it != st.end() && (*it).first <= v.second) { v.second = max(v.second, (*it).second); auto it2 = it++; st.erase(it2); } st.insert(v); } ll gcd(ll x, ll y) { if (x < y) swap(x, y); if (y == 0) return x; return gcd(y, x%y); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, x, y; cin >> n >> x >> y; ll tm = gcd(x, y+1); ll rq; if (x / tm > ((ll)1e18)/y) rq = (ll)1e18; else rq = (x / tm) * y; iloop(0, n) { cin >> x >> y; if (x + rq <= y + 1) {ins({0, rq-1}); break;} x %= rq, y %= rq; if (x <= y) ins({x, y}); else ins({x, rq-1}), ins({0, y}); } ll cs = 0; for (auto it : st) cs += it.second - it.first + 1; cout << cs; }
#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...