#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using pb = pair<bool, bool>;
using vpb = vector<pb>;
using vvpb = vector<vpb>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) a = min(a, b)
#define upmax(a, b) a = max(a, b)
#define pr(x) cout << x << endl;
#define prv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define prvv(v) for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define wpr(x) cout << #x << " = " << (x) << endl;
#define wprv(v) cout << #v << ": " << endl; for(auto it : v) cout << *it << " "; cout << endl;
#define wprvv(v) cout << #v << ": " << endl; for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define rep(i,s,e) for(ll i = s; i < e; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
ll n, A, B;
struct SEG {
vb a;
ll sz;
void make(ll n) {
for (sz = 1; sz < n; sz <<= 1);
a.resize(sz * 2, 0);
}
void up(ll l, ll r) {
l += sz, r += sz;
while (l <= r) {
if (l % 2 == 1) a[l++] = 1;
if (r % 2 == 0) a[r--] = 1;
l >>= 1, r >>= 1;
}
}
ll get(ll i) {
for (i += sz; i; i >>= 1) {
if (a[i]) return 1;
}
return 0;
}
ll q(ll l, ll r) {
l += sz, r += sz;
ll res = 0;
while (l <= r) {
if (l % 2 == 1) res |= a[l++];
if (r % 2 == 0) res |= a[r--];
l >>= 1, r >>= 1;
}
return res;
}
};
ll x(ll t)
{
return (t + t / B) % A;
}
ll y(ll t)
{
return t % B;
}
void solve()
{
cin >> n >> A >> B;
SEG seg;
seg.make(A * B);
rep(i, 0, n) {
ll l, r;
cin >> l >> r;
ll d = (r - l + 1);
if (d >= A * B - 1) {
seg.up(0, A * B - 1);
continue;
}
l %= A * B;
r %= A * B;
if (l <= r) {
seg.up(l, r);
}
else {
seg.up(l, A * B - 1);
seg.up(0, r);
}
}
ll ans = 0;
rep(i, 0, A* B) {
ans += seg.get(i);
}
pr(ans);
}
int main()
{
FAST;
FASTIN; FASTOUT;
solve();
}
/*
3 3 3
4 4
7 9
17 18
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
131 ms |
2628 KB |
Output is correct |
3 |
Correct |
102 ms |
2728 KB |
Output is correct |
4 |
Incorrect |
13 ms |
432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2867 ms |
33144 KB |
Output is correct |
3 |
Correct |
4105 ms |
33140 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
13 ms |
592 KB |
Output is correct |
3 |
Correct |
14 ms |
588 KB |
Output is correct |
4 |
Correct |
11 ms |
584 KB |
Output is correct |
5 |
Correct |
390 ms |
7132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
411 ms |
816 KB |
Output is correct |
3 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
411 ms |
816 KB |
Output is correct |
3 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
411 ms |
816 KB |
Output is correct |
3 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
5025 ms |
266660 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
131 ms |
2628 KB |
Output is correct |
3 |
Correct |
102 ms |
2728 KB |
Output is correct |
4 |
Incorrect |
13 ms |
432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |