# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874469 |
2023-11-17T06:35:45 Z |
josanneo22 |
Pairs (IOI07_pairs) |
C++17 |
|
39 ms |
11020 KB |
/*
Problem: IOI 2007 Pairs
When: 2023-11-16 14:54:19
Author: Ning07
*/
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
const int NN=2e5;
int N,B,M,D,a[NN],x[NN],y[NN];
void solve1(){
for(int i=0;i<N;i++){
std::cin>>a[i];
}
sort(a,a+N);
i64 ans=0;
for(int i=0;i<N;i++){
int lst=lower_bound(a,a+N,a[i]-D)-a;
ans+=i-lst;
}
cout<<ans<<'\n';
}
const int lift=2e5;
i64 tr[NN<<1];
void update(int x,i64 v){
x+=lift;
for(;x;x/=2){ tr[x]+=v;}
}
i64 get(int x,int y){
x+=lift; y+=lift;
i64 res=0;
while(x<=y){
if(x%2==1) res+=tr[x++];
if(y%2==0) res+=tr[y--];
x/=2; y/=2;
}
return res;
}
void solve2(){
vector<int> pos[75000*2+500];
i64 ans=0;
for(int i=0;i<N;i++){
std::cin>>x[i]>>y[i];
pos[x[i]+y[i]].push_back(x[i]-y[i]+M);
}
for(int i=2;i<=2*M;i++){
for(auto &u:pos[i]){
ans+=get(max(0,u-D),min(2*M,u+D));
update(u,1);
}
if(i-D<=0) continue;
for(auto &u:pos[i-D]) update(u,-1);
}
cout<<ans<<'\n';
}
void solve3(){
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
std::cin>>B>>N>>D>>M;
if(B==1) solve1();
else if(B==2) solve2();
else if(B==3) solve3();
}
# |
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 |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
600 KB |
Output is correct |
2 |
Correct |
11 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
600 KB |
Output is correct |
2 |
Correct |
16 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
856 KB |
Output is correct |
2 |
Correct |
16 ms |
860 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
7260 KB |
Output is correct |
2 |
Correct |
15 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
7516 KB |
Output is correct |
2 |
Correct |
25 ms |
7760 KB |
Output is correct |
3 |
Correct |
23 ms |
7516 KB |
Output is correct |
4 |
Correct |
25 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11020 KB |
Output is correct |
2 |
Correct |
39 ms |
10836 KB |
Output is correct |
3 |
Correct |
27 ms |
9564 KB |
Output is correct |
4 |
Correct |
26 ms |
9696 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 |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |