# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
762754 |
2023-06-21T17:30:00 Z |
caganyanmaz |
Pairs (IOI07_pairs) |
C++17 |
|
198 ms |
46252 KB |
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
using namespace std;
struct SegTree
{
int n;
vector<int> data, left, right;
SegTree(int n) : n(n), data(1, 0), left(1, -1), right(1, -1) {}
void cc(int index)
{
if (left[index] == -1)
{
left[index] = data.size();
data.pb(0);
left.pb(-1);
right.pb(-1);
}
if (right[index] == -1)
{
right[index] = data.size();
data.pb(0);
left.pb(-1);
right.pb(-1);
}
}
void update(int l, int r, int index, int i, int val)
{
if (i >= r || l > i)
return;
if (l + 1 == r)
{
data[index] += val;
return;
}
cc(index);
int m = l+r>>1;
update(l, m, left[index], i, val);
update(m, r, right[index], i, val);
data[index] = data[left[index]] + data[right[index]];
}
int get(int l, int r, int index, int ss, int ee)
{
if (ss >= r || l >= ee)
return 0;
if (ee >= r && l >= ss)
return data[index];
int m = l+r>>1;
int lres = 0, rres = 0;
if (left[index] != -1)
lres = get(l, m, left[index], ss, ee);
if (right[index] != -1)
rres = get(m, r, right[index], ss, ee);
return lres + rres;
}
void update(int i, int val) { update(0, n, 0, i, val ); }
int get(int ss, int ee) { return get(0, n, 0, ss, ee); }
};
void solve1d()
{
int n, d, m;
cin >> n >> d >> m;
SegTree st(m);
vector<int> v(n);
for (int& i : v)
{
cin >> i;
st.update(i, 1);
}
int encounters = 0;
for (int i : v)
encounters += st.get(i-d, i+d+1) - 1;
//assert(encounters % 2 == 0);
cout << (encounters / 2) << "\n";
}
int32_t main()
{
int b;
cin >> b;
assert(b == 1);
solve1d();
}
Compilation message
pairs.cpp: In member function 'void SegTree::update(int64_t, int64_t, int64_t, int64_t, int64_t)':
pairs.cpp:39:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l+r>>1;
| ~^~
pairs.cpp: In member function 'int64_t SegTree::get(int64_t, int64_t, int64_t, int64_t, int64_t)':
pairs.cpp:50:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int m = l+r>>1;
| ~^~
# |
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 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
46192 KB |
Output is correct |
2 |
Correct |
122 ms |
46252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
46156 KB |
Output is correct |
2 |
Correct |
106 ms |
9368 KB |
Output is correct |
3 |
Correct |
67 ms |
2332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |