# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1261870 | wedonttalkanymore | Strange Device (APIO19_strange_device) | C++20 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 16;
int n, A, B;
map <__int128_t, int> mp;
string convert(__int128_t x) {
string s = "";
while(x > 0) {
int t = x % 10;
s += char(t + '0');
x /= 10;
}
reverse(s.begin(), s.end());
return s;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> A >> B;
int t = __gcd(A, B + 1);
int x = A / t;
__int128_t L = __int128_t(x) * __int128_t(B); // chu ki
mp[0] = mp[L] = 0;
for (int i = 1; i <= n; i++) {
int l, r;
cin >> l >> r;
if (L <= r - l + 1) {
convert(L);
// cout << 1;
return 0;
}
mp[l % L]++, mp[r % L + 1]--;
if (l % L > r % L) mp[0]++, mp[L]--;
}
int ans = 0, last = 0, sum = 0;
for (auto [id, val] : mp) {
if (sum) {
ans += id - last;
}
sum += val;
last = id;
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |