# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
501091 |
2022-01-02T10:56:46 Z |
600Mihnea |
Pairs (IOI07_pairs) |
C++17 |
|
4000 ms |
210356 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen ("input", "r", stdin);
int B;
cin >> B;
///assert(B == 1 || B == 2 || B == 3);
if (B == 1) {
int n, d, _;
cin >> n >> d >> _;
vector<int> a(n);
for (auto &x : a) {
cin >> x;
}
sort(a.begin(), a.end());
ll sol = 0;
int C = 0, c = 0;
for (int i = 0; i < n; i++) {
int low = a[i] - d, high = a[i] + d;
while (C < n && a[C] <= high) {
C++;
}
while (c < n && a[c] < low) {
c++;
}
sol += C - c;
}
sol -= n;
sol /= 2;
cout << sol << "\n";
exit(0);
}
if (B == 2) {
/// aib 2d
int n, d, L;
cin >> n >> d >> L;
L *= 2;
vector<map<int, int>> guys(L + 1);
vector<vector<int>> aib(L + 1);
function<void(int, int)> prep_get = [&] (int a, int b) {
if (a < 0) a = 0;
if (b < 0) b = 0;
if (a > L) a = L;
if (b > L) b = L;
if (!a || !b) return;
int sol = 0;
for (int i = a; i >= 1; i -= i & (-i)) {
guys[i][b] = 0;
}
};
function<void(int, int, int)> prep_add = [&] (int a, int b, int x) {
assert(1 <= a && a <= L);
assert(1 <= b && b <= L);
for (int i = a; i <= L; i += i & (-i)) {
guys[i][b] = 0;
}
};
function<int(int, int)> get = [&] (int a, int b) {
if (a < 0) a = 0;
if (b < 0) b = 0;
if (a > L) a = L;
if (b > L) b = L;
if (!a || !b) return 0;
int sol = 0;
for (int i = a; i >= 1; i -= i & (-i)) {
assert(guys[i].count(b));
for (int j = guys[i][b]; j >= 1; j -= j & (-j)) {
sol += aib[i][j];
}
}
return sol;
};
function<void(int, int, int)> add = [&] (int a, int b, int x) {
assert(1 <= a && a <= L);
assert(1 <= b && b <= L);
for (int i = a; i <= L; i += i & (-i)) {
assert(guys[i].count(b));
for (int j = guys[i][b]; j < (int) aib[i].size(); j += j & (-j)) {
aib[i][j] += x;
}
}
};
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
int xx, yy;
cin >> xx >> yy;
x[i] = xx + yy;
y[i] = xx - yy + L / 2;
prep_add(x[i], y[i], 1);
prep_get(x[i] + d, y[i] + d);
prep_get(x[i] - d - 1, y[i] + d);
prep_get(x[i] + d, y[i] - d - 1);
prep_get(x[i] - d - 1, y[i] - d - 1);
}
for (int i = 0; i <= L; i++) {
int cur = 0;
for (auto &it : guys[i]) {
cur++;
it.second = cur;
}
aib[i].resize(cur + 1);
}
for (int i = 0; i < n; i++) {
add(x[i], y[i], 1);
}
ll sol = 0;
for (int i = 0; i < n; i++) {
sol += get(x[i] + d, y[i] + d) - get(x[i] - d - 1, y[i] + d) - get(x[i] + d, y[i] - d - 1) + get(x[i] - d - 1, y[i] - d - 1);
}
sol -= n;
sol /= 2;
cout << sol << "\n";
exit(0);
}
assert(0);
return 0;
}
Compilation message
pairs.cpp: In lambda function:
pairs.cpp:56:11: warning: unused variable 'sol' [-Wunused-variable]
56 | int sol = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
964 KB |
Output is correct |
2 |
Correct |
11 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1204 KB |
Output is correct |
2 |
Correct |
18 ms |
1212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1204 KB |
Output is correct |
2 |
Correct |
19 ms |
1232 KB |
Output is correct |
3 |
Correct |
16 ms |
1204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
17280 KB |
Output is correct |
2 |
Correct |
23 ms |
17676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
381 ms |
2832 KB |
Output is correct |
2 |
Correct |
119 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2319 ms |
47256 KB |
Output is correct |
2 |
Correct |
1807 ms |
42308 KB |
Output is correct |
3 |
Correct |
1791 ms |
40480 KB |
Output is correct |
4 |
Correct |
1562 ms |
36536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4027 ms |
210356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
440 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
452 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
452 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |