# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382521 | 2021-03-27T14:47:04 Z | talant117408 | Strange Device (APIO19_strange_device) | C++17 | 485 ms | 69724 KB |
/* Code written by Talant I.D. */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; const int mod = 1e9+7; ll mode(ll a) { a %= mod; if (a < 0) a += mod; return a; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) res = mult(res, a); a = mult(a, a); b >>= 1; } return res; } void usaco(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } ll n, a, b; ll A(ll x) { return (x+x/b)%a; } ll B(ll x) { return x%b; } int main() { do_not_disturb //~ usaco("dirtraverse"); ll sum = 0; cin >> n >> a >> b; vector <pll> v(n), segs; for (auto &to : v) cin >> to.first >> to.second; for (auto to : v) sum += (to.second-to.first+1); if (sum <= 1e6+7) { set <pll> st; for (auto to : v) { for (ll j = to.first; j <= to.second; j++) { st.insert(mp((j+j/b)%a, j%b)); } } cout << sz(st) << endl; } else if (b < 4 || a*b <= 1e6) { ll t = a*b; vector <pll> segs; bool flag = 0; for (auto to : v) { if (to.first/t == to.second/t) { segs.pb(mp(to.first%t, to.second%t)); } else if (to.first/t+1 == to.second/t) { segs.pb(mp(to.first%t, t-1)); segs.pb(mp(0, to.second%t)); } else { flag = 1; } } if (flag) cout << t << endl; else { ll ans = 0; sort(all(segs)); for (int i = 0, j = 0; i < sz(segs); i = j) { auto l = segs[i].first, r = segs[i].second; for ( ; j < sz(segs) && segs[j].first <= r; j++) { r = max(r, segs[j].second); } ans += r-l+1; } cout << ans << endl; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 46 ms | 12524 KB | Output is correct |
3 | Correct | 70 ms | 18156 KB | Output is correct |
4 | Correct | 3 ms | 876 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 8 ms | 1260 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 44 ms | 7020 KB | Output is correct |
16 | Correct | 29 ms | 6892 KB | Output is correct |
17 | Correct | 62 ms | 8172 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 137 ms | 32296 KB | Output is correct |
3 | Correct | 190 ms | 32108 KB | Output is correct |
4 | Correct | 123 ms | 30572 KB | Output is correct |
5 | Correct | 348 ms | 32544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 472 ms | 32604 KB | Output is correct |
3 | Incorrect | 485 ms | 69724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 472 ms | 32604 KB | Output is correct |
3 | Incorrect | 485 ms | 69724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 472 ms | 32604 KB | Output is correct |
3 | Incorrect | 485 ms | 69724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 41 ms | 1900 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 46 ms | 12524 KB | Output is correct |
3 | Correct | 70 ms | 18156 KB | Output is correct |
4 | Correct | 3 ms | 876 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 8 ms | 1260 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 44 ms | 7020 KB | Output is correct |
16 | Correct | 29 ms | 6892 KB | Output is correct |
17 | Correct | 62 ms | 8172 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Incorrect | 1 ms | 364 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |