#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
int clever(int n, int a, int b, vector<pair<int, int>> &seg) {
long double k1 = a * (long double) b;
int k = (int) 1e18 + 1;
if (k1 <= 1e18) {
k = a;
}
vector<pair<int, int>> segs;
for (int i = 0; i < n; i++) {
int l = seg[i].first, r = seg[i].second;
if (r - l + 1 >= k) {
segs.emplace_back(0, k - 1);
continue;
}
int l1 = l % k, r1 = r % k;
if (r1 < l1) {
segs.emplace_back(0, r1);
segs.emplace_back(l1, k - 1);
} else {
segs.emplace_back(l1, r1);
}
}
sort(segs.begin(), segs.end());
int mxr = -1;
int res = 0;
for (auto x : segs) {
res += max(x.second - max(mxr, x.first - 1), 0LL);
mxr = max(x.second, mxr);
}
return res;
}
int stupid(int n, int a, int b, vector<pair<int, int>> &seg) {
set<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
int l = seg[i].first, r = seg[i].second;
for (int j = l; j <= r; j++) {
ans.insert({(j + j / b) % a, j % b});
}
}
return ans.size();
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
vector<pair<int, int>> seg(n);
for (auto &x : seg) {
cin >> x.first >> x.second;
}
cout << stupid(n, a, b, seg) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
53 ms |
12536 KB |
Output is correct |
3 |
Correct |
76 ms |
18168 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
12 ms |
1280 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
50 ms |
7032 KB |
Output is correct |
16 |
Correct |
44 ms |
7288 KB |
Output is correct |
17 |
Correct |
76 ms |
11896 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Runtime error |
2602 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
142 ms |
32376 KB |
Output is correct |
3 |
Correct |
202 ms |
32120 KB |
Output is correct |
4 |
Correct |
124 ms |
30584 KB |
Output is correct |
5 |
Execution timed out |
5058 ms |
78456 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
78620 KB |
Output is correct |
3 |
Runtime error |
2369 ms |
524288 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
78620 KB |
Output is correct |
3 |
Runtime error |
2369 ms |
524288 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
78620 KB |
Output is correct |
3 |
Runtime error |
2369 ms |
524288 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Runtime error |
1495 ms |
524288 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
53 ms |
12536 KB |
Output is correct |
3 |
Correct |
76 ms |
18168 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
12 ms |
1280 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
50 ms |
7032 KB |
Output is correct |
16 |
Correct |
44 ms |
7288 KB |
Output is correct |
17 |
Correct |
76 ms |
11896 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Runtime error |
2602 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
21 |
Halted |
0 ms |
0 KB |
- |