# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
888182 |
2023-12-16T09:52:54 Z |
Macker |
Pairs (IOI07_pairs) |
C++17 |
|
130 ms |
12608 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 + 1});
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
11272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
12376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
12608 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 |
1 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 |
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 |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |