| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1279693 | swishy123 | Strange Device (APIO19_strange_device) | C++20 | 2384 ms | 589824 KiB |
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define x first
#define y second
const ll inf = 1e18;
const int def = 1e5+1;
using namespace std;
typedef __int128_t i128;
void solve(){
ll n, A, B;
cin >> n >> A >> B;
ll g = gcd(A, B + 1);
i128 x = A / g;
i128 cycle = (i128)B * x;
map<pi, int> mp;
for (int i = 0; i < A * B; i++){
int x = (i + i / B) % A;
int y = i % B;
mp[{x, y}] = 1;
}
cycle = mp.size();
vector<pl> sm;
for (int i = 0; i < n; i++){
ll l, r;
cin >> l >> r;
l %= cycle; r %= cycle;
if (l <= r)
sm.push_back({l, r});
else{
sm.push_back({l, cycle - 1});
sm.push_back({0, r});
}
}
sort(sm.begin(), sm.end());
ll res = 0, max_r = -inf;
for (int i = 0; i < sm.size(); i++){
auto [l, r] = sm[i];
max_r = max(max_r, l - 1);
res += r - max_r;
max_r = max(max_r, r);
}
cout << res;
}
/*
find x so that (b + 1) * x mod a = 0
1 20
0 18
39 48
*/
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (ifstream("input.txt").good()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int t;
t = 1;
while (t--){
solve();
}
}
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... | ||||
