# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
550775 |
2022-04-19T07:36:04 Z |
Jomnoi |
Pairs (IOI07_pairs) |
C++17 |
|
48 ms |
9188 KB |
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
// B = 1
long long solve1(int N, int D, int M) {
vector <int> X(N + 1);
for(int i = 1; i <= N; i++) {
cin >> X[i];
}
sort(X.begin() + 1, X.end());
long long ans = 0;
for(int l = 1, r = 1; r <= N; r++) {
while(l < r and X[r] - X[l] > D) {
l++;
}
ans += r - l;
}
return ans;
}
// B = 2
class FenwickTree {
private :
int N;
vector <int> fenwick;
public :
FenwickTree() {}
FenwickTree(const int &n) : N(n), fenwick(N + 1, 0) {}
void add(const int &idx, const int &v) {
for(int i = idx; i <= N; i += (i & -i)) {
fenwick[i] += v;
}
}
int get(const int &idx) {
int res = 0;
for(int i = idx; i >= 1; i -= (i & -i)) {
res += fenwick[i];
}
return res;
}
};
class Query {
public :
int x, y, t;
Query() {}
Query(const int &x_, const int &y_, const int &t_) : x(x_), y(y_), t(t_) {}
bool operator<(const Query &o) const {
if(x == o.x) {
if(y == o.y) {
return t < o.t;
}
return y < o.y;
}
return x < o.x;
}
};
long long solve2(int N, int D, int M) {
FenwickTree fw(2 * M);
vector <int> X(N + 1, 0), Y(N + 1, 0);
for(int i = 1; i <= N; i++) {
cin >> X[i] >> Y[i];
}
vector <Query> query;
for(int i = 1; i <= N; i++) {
query.push_back(Query(X[i] - Y[i], X[i] + Y[i], 1));
query.push_back(Query(X[i] - Y[i] + D + 1, X[i] + Y[i], -1));
}
sort(query.begin(), query.end());
long long ans = 0;
for(auto [x, y, t] : query) {
if(t == -1) {
fw.add(y, -1);
}
else if(t == 1) {
ans += fw.get(y + D) - fw.get(y - D - 1);
fw.add(y, 1);
}
}
return ans;
}
// B = 3
long long solve3(int N, int D, int M) {
return -1;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int B, N, D, M;
cin >> B >> N >> D >> M;
if(B == 1) {
cout << solve1(N, D, M);
}
else if(B == 2) {
cout << solve2(N, D, M);
}
else if(B == 3) {
cout << solve3(N, D, M);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
724 KB |
Output is correct |
2 |
Correct |
22 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
596 KB |
Output is correct |
2 |
Correct |
21 ms |
724 KB |
Output is correct |
3 |
Correct |
16 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1748 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
4840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
5064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
9188 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |