# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874634 |
2023-11-17T12:49:49 Z |
josanneo22 |
Pairs (IOI07_pairs) |
C++17 |
|
48 ms |
10656 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;
constexpr 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;
}
std::cout<<ans<<'\n';
}
i64 tr[NN<<1];
void update(int x,i64 v){
x+=NN;
for(;x;x=x/=2){ tr[x]+=v;}
}
i64 get(int x,int y){
x+=NN; y+=NN;
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);
}
std::cout<<ans<<'\n';
}
void solve3(){
std::cout<<"fck this subtask\n";
}
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();
}
Compilation message
pairs.cpp: In function 'void update(int, i64)':
pairs.cpp:29:13: warning: operation on 'x' may be undefined [-Wsequence-point]
29 | for(;x;x=x/=2){ tr[x]+=v;}
| ~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1116 KB |
Output is correct |
2 |
Correct |
12 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1596 KB |
Output is correct |
2 |
Correct |
14 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1600 KB |
Output is correct |
2 |
Correct |
20 ms |
1444 KB |
Output is correct |
3 |
Correct |
15 ms |
1472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
4 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 |
7200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
7260 KB |
Output is correct |
2 |
Correct |
24 ms |
7376 KB |
Output is correct |
3 |
Correct |
25 ms |
7768 KB |
Output is correct |
4 |
Correct |
23 ms |
7256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
10656 KB |
Output is correct |
2 |
Correct |
48 ms |
10612 KB |
Output is correct |
3 |
Correct |
29 ms |
9328 KB |
Output is correct |
4 |
Correct |
27 ms |
9284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
544 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 |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |