# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
620006 |
2022-08-02T18:36:38 Z |
1ne |
Pairs (IOI07_pairs) |
C++14 |
|
415 ms |
293756 KB |
#include<bits/stdc++.h>
using namespace std;
struct dataa{
long long v = 0;
void add(long long left,long long right,long long val){
v+=val;
//sum += val *(right - left + 1);
}
};
long long S,T;
struct Segment_Tree{
vector<dataa>tree;
void init(long long n){
tree.resize(2*n - 1);
}
dataa combine(dataa left,dataa right){
dataa res;
res.v = left.v + right.v;
return res;
}
long long query(long long node,long long left,long long right,long long qleft,long long qright){
if (qright<left|| qleft > right)return 0;
if (qleft<=left && qright>=right){
return tree[node].v;
}
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
return query(node + 1,left,mid,qleft,qright) + query(z,mid + 1,right,qleft,qright);
}
void update(long long node,long long left,long long right,long long uleft,long long uright,long long v){
if (left > uright || right < uleft) return;
if (uleft <= left && right <=uright){
tree[node].add(left,right,v);
return;
}
long long mid = (left + right)>>1;
long long z = node + ((mid - left + 1)<<1);
if (uleft<=mid){
update(node + 1,left,mid,uleft,uright,v);
}
if (uright > mid){
update(z,mid + 1,right,uleft,uright,v);
}
tree[node] = combine(tree[node + 1],tree[z]);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int b,n,d,m;cin>>b>>n>>d>>m;
if (b == 1){
vector<int>arr(m + 1,0);
for (int i = 0;i<n;++i){
int a;cin>>a;
arr[a]++;
}
for (int i = 1;i<=m;++i){
arr[i]+=arr[i - 1];
}
long long ans = arr[d] * (arr[d] - 1)/2;
for (int i = d + 1;i<=m;++i){
//cout<<i<<" "<<(arr[i] - arr[i - 1])<<" "<<arr[i - 1] - arr[i - d - 1]<<'\n';
long long pos = (arr[i] - arr[i - 1]) * (arr[i - 1] - arr[i - d - 1]);
ans+=pos;
ans+=(arr[i] - arr[i - 1]) * (arr[i] - arr[i - 1] - 1)/2;
}
cout<<ans<<'\n';
}
else if (b == 2){
vector<int>arr(n),brr(n);
for (int i = 0;i<n;++i){
int x,y;cin>>x>>y;
arr[i] = x + y;
brr[i] = x - y + m;
}
vector<int>order(n);
iota(order.begin(),order.end(),0);
sort(order.begin(),order.end(),[&](int i,int j){
return arr[i] < arr[j];
});
long long ans = 0;
Segment_Tree st;
st.init(m * 2 + 1);
int l = 0;
for (int i = 0;i<n;++i){
while(l<n && arr[order[l]] - arr[order[i]]<=d){st.update(0,0,m * 2,brr[order[l]],brr[order[l]],1);++l;}
ans+=st.query(0,0,m * 2,brr[order[i]] - d,brr[order[i]] + d);
st.update(0,0,m * 2,brr[order[i]],brr[order[i]],-1);
}
cout<<ans - n<<'\n';
}
else{
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
293756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
596 KB |
Output is correct |
2 |
Incorrect |
7 ms |
684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
415 ms |
275044 KB |
Output is correct |
2 |
Incorrect |
298 ms |
275140 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
275072 KB |
Output is correct |
2 |
Correct |
383 ms |
275064 KB |
Output is correct |
3 |
Correct |
380 ms |
275092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
1996 KB |
Output is correct |
2 |
Correct |
34 ms |
2076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
2268 KB |
Output is correct |
2 |
Correct |
57 ms |
2292 KB |
Output is correct |
3 |
Correct |
55 ms |
2260 KB |
Output is correct |
4 |
Correct |
61 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
4828 KB |
Output is correct |
2 |
Correct |
88 ms |
4828 KB |
Output is correct |
3 |
Correct |
64 ms |
4828 KB |
Output is correct |
4 |
Correct |
83 ms |
4800 KB |
Output is correct |
# |
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 |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |