# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
888185 |
2023-12-16T09:53:27 Z |
Macker |
Pairs (IOI07_pairs) |
C++17 |
|
133 ms |
12376 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
class Seg{
vector<ll> st;
int len = 1;
public:
Seg(int n){
while(len < n) len *= 2;
st.resize(len * 2, 0);
}
void add(int idx, ll val, int i, int s, int e){
if(idx < s || idx >= e) return;
if(idx == s && s + 1 == e){
st[i] += val;
return;
}
add(idx, val, i * 2, s, (s + e) / 2);
add(idx, val, i * 2 + 1, (s + e) / 2, e);
st[i] = st[i * 2] + st[i * 2 + 1];
}
void add(int idx, ll val){
add(idx, val, 1, 0, len);
}
ll qry(int l, int r, int i, int s, int e){
if(l >= e || s >= r) return 0;
if(l <= s && e <= r) return st[i];
return qry(l, r, i * 2, s, (s + e) / 2) + qry(l, r, i * 2 + 1, (s + e) / 2, e);
}
ll qry(int l, int r){
return qry(l, r, 1, 0, len);
}
};
vector<int> coords;
int cmpr(int x){
return lower_bound(all(coords), x) - coords.begin();
}
int main()
{
int b, n, d, m; cin >> b >> n >> d >> m;
if(b == 1){
vector<pair<int, int>> q;
vector<int> ad;
for (int i = 0; i < n; i++) {
int a; cin >> a;
ad.push_back(a);
q.push_back({a - d, a + d});
coords.push_back(a);
coords.push_back(a - d);
coords.push_back(a + d);
}
sort(all(coords));
Seg st(coords.size() + 1);
for (auto &i : ad)
st.add(cmpr(i), 1);
ll res = 0;
for (auto &[f, t] : q)
res += st.qry(cmpr(f), cmpr(t) + 1) - 1;
cout << res / 2 << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
11512 KB |
Output is correct |
2 |
Correct |
102 ms |
11336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
11504 KB |
Output is correct |
2 |
Correct |
124 ms |
12352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
11328 KB |
Output is correct |
2 |
Correct |
133 ms |
12348 KB |
Output is correct |
3 |
Correct |
124 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |