# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
620012 |
2022-08-02T18:45:16 Z |
1ne |
Pairs (IOI07_pairs) |
C++14 |
|
4000 ms |
293804 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 + 5);
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 + 4,brr[order[l]],brr[order[l]],1);++l;}
ans+=st.query(0,0,m * 2 + 4,brr[order[i]] - d,brr[order[i]] + d);
st.update(0,0,m * 2 + 4,brr[order[i]],brr[order[i]],-1);
}
cout<<ans - n<<'\n';
}
else{
long long ans = 0;
vector<vector<int>>arr(n,vector<int>(3));
for (int i = 0;i<n;++i){
for (int j = 0;j<3;++j){
cin>>arr[i][j];
}
}
for (int i = 0;i<n;++i){
for (int j = i + 1;j<n;++j){
long long sum = abs(arr[i][0] - arr[j][0]) + abs(arr[i][1] - arr[j][1]) + abs(arr[i][2] - arr[j][2]);
if (sum<=d)ans++;
}
}
cout<<ans<<'\n';
}
return 0;
}
# |
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 |
407 ms |
293804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
212 KB |
Output is correct |
2 |
Incorrect |
8 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
274252 KB |
Output is correct |
2 |
Incorrect |
294 ms |
274260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
274272 KB |
Output is correct |
2 |
Correct |
382 ms |
274252 KB |
Output is correct |
3 |
Correct |
403 ms |
274244 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 |
36 ms |
1500 KB |
Output is correct |
2 |
Correct |
31 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1516 KB |
Output is correct |
2 |
Correct |
66 ms |
1532 KB |
Output is correct |
3 |
Correct |
58 ms |
1504 KB |
Output is correct |
4 |
Correct |
52 ms |
1504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
3800 KB |
Output is correct |
2 |
Correct |
87 ms |
3680 KB |
Output is correct |
3 |
Correct |
83 ms |
3656 KB |
Output is correct |
4 |
Correct |
70 ms |
3660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4013 ms |
5716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4056 ms |
5716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4051 ms |
5716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |