# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
714092 |
2023-03-23T21:47:30 Z |
SlavicG |
Pairs (IOI07_pairs) |
C++17 |
|
37 ms |
4616 KB |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define int long long
const int N = 1e6;
int fen[N];
void modif(int u, int val) {
for(int i = u + 1; i < N; i += i & -i) fen[i] += val;
}
int query(int l, int r) {
int ans = 0;
for(int i = r + 1; i >= 1; i -= i & -i) ans += fen[i];
for(int i = l; i >= 1; i -= i & -i) ans -= fen[i];
return ans;
}
void solve() {
int b, n, d, m; cin >> b >> n >> d >> m;
if(b == 1) {
vector<int> a(n);
for(int i = 0; i < n; ++i) cin >> a[i];
sort(all(a));
int ans = 0;
for(int i = 0; i < n; ++i) {
int j = upper_bound(all(a), a[i] + d) - a.begin();
ans += j - i - 1;
}
cout << ans << "\n";
} else if(b == 2) {
vector<pair<int, int>> a;
for(int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
a.pb({x - y, x + y});
}
queue<int> q;
sort(all(a));
int ans = 0;
for(int i = 0; i < n; ++i) {
while(!q.empty() && abs(a[i].first - a[q.front()].first) > d) {
modif(a[q.front()].second, -1);
q.pop();
}
ans += query(a[i].second - d, min(a[i].second + d, N - 2));
q.push(i);
modif(a[i].second, 1);
}
cout << ans << "\n";
} else {
assert(false);
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1108 KB |
Output is correct |
2 |
Correct |
13 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1108 KB |
Output is correct |
2 |
Correct |
17 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1108 KB |
Output is correct |
2 |
Correct |
19 ms |
1108 KB |
Output is correct |
3 |
Correct |
17 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
2 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2512 KB |
Output is correct |
2 |
Correct |
27 ms |
3296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2532 KB |
Output is correct |
2 |
Correct |
33 ms |
3228 KB |
Output is correct |
3 |
Correct |
37 ms |
3176 KB |
Output is correct |
4 |
Correct |
34 ms |
3172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3136 KB |
Output is correct |
2 |
Correct |
33 ms |
4616 KB |
Output is correct |
3 |
Correct |
35 ms |
4500 KB |
Output is correct |
4 |
Correct |
33 ms |
4416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |