#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define sz size()
const int N = 2e5 + 1;
using namespace std;
ll n, a, b, ans = 0;
set <pii> s;
vector <pii> v;
int main(){
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
ll x, y;
cin >> x >> y;
if(b == 1){
if(y - x + 1 >= a) return cout << a,0;
ll san = (2*x) % a, san1 = (2*y) % a;
if(san <= san1){
v.pb({san,1});
v.pb({san1,0});
}
else{
v.pb({0,1});
v.pb({san1,0});
v.pb({san,1});
v.pb({a-1,0});
}
continue;
}
for(ll j = x; j <= y; j++){
ll san = j + j/b;
san %= a;
int san1 = j % b;
s.insert({san,san1});
}
ans = (int)s.sz;
}
if(b == 1){
sort(v.begin(), v.end());
ll ac = 0, bas = 1e18;
for(auto i: v){
if(i.ss == 1){
ac++;
bas = min(bas,i.ff);
}
else{
ac--;
if(ac == 0){
ans += i.ff - bas + 1;
bas = 1e18;
}
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
35 ms |
12624 KB |
Output is correct |
3 |
Correct |
46 ms |
18260 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1674 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
83 ms |
32400 KB |
Output is correct |
3 |
Correct |
110 ms |
32084 KB |
Output is correct |
4 |
Correct |
73 ms |
30548 KB |
Output is correct |
5 |
Execution timed out |
5052 ms |
62544 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
966 ms |
68744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
966 ms |
68744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
966 ms |
68744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1027 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
35 ms |
12624 KB |
Output is correct |
3 |
Correct |
46 ms |
18260 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |