# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932242 | 2024-02-23T06:11:04 Z | Baizho | Strange Device (APIO19_strange_device) | C++14 | 446 ms | 53856 KB |
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // #pragma GCC optimize("Ofast,unroll-loops,fast-math") // #pragma GCC target("popcnt") typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; #define sz size() #define ff first #define ss second #define all(a) a.begin(),a.end() #define pb push_back const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6 const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod const int N = ll(2e3)+100; const int M = ll(2e5) + 100; const long long inf = 5e18; const long double eps = 1e-15L; ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; } ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;} void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); } #define int ll void Baizho() { int n, a, b; cin>>n>>a>>b; int siz = a / __gcd(a, b + 1); if(siz <= inf / b) siz *= b; else siz = inf; vector<pair<int, int> > range; while(n --) { int l, r; cin>>l>>r; if((r - l + 1) >= siz) { range.pb({0, siz - 1}); continue; } l %= siz; r %= siz; if(l <= r) { range.pb({l, r}); } else { range.pb({0, r}); range.pb({l, siz - 1}); } } sort(all(range)); int maxr = -1, ans = 0; for(auto c : range) { if(maxr < c.ff) { // new segment started ans += c.ss - c.ff + 1; maxr = c.ss; } else if(c.ff <= maxr && maxr <= c.ss) { // not completely new ans += c.ss - maxr; maxr = c.ss; } } cout<<ans<<"\n"; } signed main() { // Freopen("nondec"); ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); // precalc(); int ttt = 1; // cin>>ttt; for(int i=1; i<=ttt; i++) {Baizho(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 3 ms | 688 KB | Output is correct |
3 | Correct | 3 ms | 752 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 736 KB | Output is correct |
17 | Correct | 34 ms | 2648 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 206 ms | 17876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 295 ms | 18736 KB | Output is correct |
3 | Correct | 294 ms | 19184 KB | Output is correct |
4 | Correct | 290 ms | 17748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 295 ms | 18736 KB | Output is correct |
3 | Correct | 294 ms | 19184 KB | Output is correct |
4 | Correct | 290 ms | 17748 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 300 ms | 17276 KB | Output is correct |
7 | Correct | 289 ms | 17076 KB | Output is correct |
8 | Correct | 312 ms | 18612 KB | Output is correct |
9 | Correct | 313 ms | 18876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 295 ms | 18736 KB | Output is correct |
3 | Correct | 294 ms | 19184 KB | Output is correct |
4 | Correct | 290 ms | 17748 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 33 ms | 2600 KB | Output is correct |
7 | Correct | 31 ms | 2468 KB | Output is correct |
8 | Correct | 28 ms | 2520 KB | Output is correct |
9 | Correct | 29 ms | 2500 KB | Output is correct |
10 | Correct | 29 ms | 2520 KB | Output is correct |
11 | Correct | 30 ms | 2516 KB | Output is correct |
12 | Correct | 28 ms | 2520 KB | Output is correct |
13 | Correct | 31 ms | 2516 KB | Output is correct |
14 | Correct | 28 ms | 2520 KB | Output is correct |
15 | Correct | 33 ms | 2516 KB | Output is correct |
16 | Correct | 32 ms | 2516 KB | Output is correct |
17 | Correct | 29 ms | 2520 KB | Output is correct |
18 | Correct | 298 ms | 18272 KB | Output is correct |
19 | Correct | 284 ms | 17340 KB | Output is correct |
20 | Correct | 320 ms | 18360 KB | Output is correct |
21 | Correct | 32 ms | 2516 KB | Output is correct |
22 | Correct | 27 ms | 2440 KB | Output is correct |
23 | Correct | 86 ms | 9448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 32 ms | 2484 KB | Output is correct |
3 | Correct | 32 ms | 2772 KB | Output is correct |
4 | Correct | 343 ms | 17080 KB | Output is correct |
5 | Correct | 34 ms | 2516 KB | Output is correct |
6 | Correct | 31 ms | 2516 KB | Output is correct |
7 | Correct | 31 ms | 2520 KB | Output is correct |
8 | Correct | 32 ms | 2520 KB | Output is correct |
9 | Correct | 31 ms | 2520 KB | Output is correct |
10 | Correct | 39 ms | 2520 KB | Output is correct |
11 | Correct | 37 ms | 2516 KB | Output is correct |
12 | Correct | 27 ms | 2520 KB | Output is correct |
13 | Correct | 32 ms | 2520 KB | Output is correct |
14 | Correct | 324 ms | 17556 KB | Output is correct |
15 | Correct | 31 ms | 2516 KB | Output is correct |
16 | Correct | 291 ms | 18496 KB | Output is correct |
17 | Correct | 283 ms | 17336 KB | Output is correct |
18 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 3 ms | 688 KB | Output is correct |
3 | Correct | 3 ms | 752 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 736 KB | Output is correct |
17 | Correct | 34 ms | 2648 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 206 ms | 17876 KB | Output is correct |
29 | Correct | 0 ms | 344 KB | Output is correct |
30 | Correct | 295 ms | 18736 KB | Output is correct |
31 | Correct | 294 ms | 19184 KB | Output is correct |
32 | Correct | 290 ms | 17748 KB | Output is correct |
33 | Correct | 0 ms | 344 KB | Output is correct |
34 | Correct | 300 ms | 17276 KB | Output is correct |
35 | Correct | 289 ms | 17076 KB | Output is correct |
36 | Correct | 312 ms | 18612 KB | Output is correct |
37 | Correct | 313 ms | 18876 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 33 ms | 2600 KB | Output is correct |
40 | Correct | 31 ms | 2468 KB | Output is correct |
41 | Correct | 28 ms | 2520 KB | Output is correct |
42 | Correct | 29 ms | 2500 KB | Output is correct |
43 | Correct | 29 ms | 2520 KB | Output is correct |
44 | Correct | 30 ms | 2516 KB | Output is correct |
45 | Correct | 28 ms | 2520 KB | Output is correct |
46 | Correct | 31 ms | 2516 KB | Output is correct |
47 | Correct | 28 ms | 2520 KB | Output is correct |
48 | Correct | 33 ms | 2516 KB | Output is correct |
49 | Correct | 32 ms | 2516 KB | Output is correct |
50 | Correct | 29 ms | 2520 KB | Output is correct |
51 | Correct | 298 ms | 18272 KB | Output is correct |
52 | Correct | 284 ms | 17340 KB | Output is correct |
53 | Correct | 320 ms | 18360 KB | Output is correct |
54 | Correct | 32 ms | 2516 KB | Output is correct |
55 | Correct | 27 ms | 2440 KB | Output is correct |
56 | Correct | 86 ms | 9448 KB | Output is correct |
57 | Correct | 1 ms | 600 KB | Output is correct |
58 | Correct | 32 ms | 2484 KB | Output is correct |
59 | Correct | 32 ms | 2772 KB | Output is correct |
60 | Correct | 343 ms | 17080 KB | Output is correct |
61 | Correct | 34 ms | 2516 KB | Output is correct |
62 | Correct | 31 ms | 2516 KB | Output is correct |
63 | Correct | 31 ms | 2520 KB | Output is correct |
64 | Correct | 32 ms | 2520 KB | Output is correct |
65 | Correct | 31 ms | 2520 KB | Output is correct |
66 | Correct | 39 ms | 2520 KB | Output is correct |
67 | Correct | 37 ms | 2516 KB | Output is correct |
68 | Correct | 27 ms | 2520 KB | Output is correct |
69 | Correct | 32 ms | 2520 KB | Output is correct |
70 | Correct | 324 ms | 17556 KB | Output is correct |
71 | Correct | 31 ms | 2516 KB | Output is correct |
72 | Correct | 291 ms | 18496 KB | Output is correct |
73 | Correct | 283 ms | 17336 KB | Output is correct |
74 | Correct | 1 ms | 344 KB | Output is correct |
75 | Correct | 0 ms | 348 KB | Output is correct |
76 | Correct | 0 ms | 348 KB | Output is correct |
77 | Correct | 0 ms | 348 KB | Output is correct |
78 | Correct | 0 ms | 348 KB | Output is correct |
79 | Correct | 4 ms | 1128 KB | Output is correct |
80 | Correct | 354 ms | 53308 KB | Output is correct |
81 | Correct | 446 ms | 53488 KB | Output is correct |
82 | Correct | 336 ms | 53364 KB | Output is correct |
83 | Correct | 343 ms | 53560 KB | Output is correct |
84 | Correct | 332 ms | 53856 KB | Output is correct |
85 | Correct | 329 ms | 53496 KB | Output is correct |
86 | Correct | 89 ms | 20160 KB | Output is correct |
87 | Correct | 1 ms | 348 KB | Output is correct |