# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
379295 | 2021-03-17T21:55:51 Z | MilosMilutinovic | Pairs (IOI07_pairs) | C++14 | 46 ms | 4076 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long int n,d,m; void Solve1D(){ vector<int> x(n); for(int i=0;i<n;i++)scanf("%i",&x[i]); sort(x.begin(),x.end()); ll ans=0; for(int i=0;i<n;i++){ int bot=i,top=n-1,pos=i; while(bot<=top){ int mid=bot+top>>1; if(x[mid]-x[i]<=d)pos=mid,bot=mid+1; else top=mid-1; } ans+=pos-i; } printf("%lld",ans); } const int N=200050; int bit[N]; void Add(int x,int f){ for(;x<N;x+=x&-x){ bit[x]+=f; } } int Get(int x){ int res=0; for(;x;x-=x&-x){ res+=bit[x]; } return res; } void Solve2D(){ vector<int> x(n),y(n),sum(n),dif(n); for(int i=0;i<n;i++)scanf("%i%i",&x[i],&y[i]),sum[i]=x[i]+y[i],dif[i]=x[i]-y[i]; vector<int> id(n); iota(id.begin(),id.end(),0); sort(id.begin(),id.end(),[&](int i,int j){ return dif[i]<dif[j]; }); int j=0; ll ans=0; for(int i=0;i<n;i++){ while(dif[id[i]]-dif[id[j]]>d){ Add(sum[id[j]],-1); j++; } ans+=Get(min(N-1,sum[id[i]]+d))-Get(max(1,sum[id[i]]-d-1)); Add(sum[id[i]],1); } printf("%lld",ans); } int main(){ int b;scanf("%i%i%i%i",&b,&n,&d,&m); if(b==1)Solve1D(); if(b==2)Solve2D(); //if(b==3)Solve3D(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 748 KB | Output is correct |
2 | Correct | 18 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 748 KB | Output is correct |
2 | Correct | 24 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 748 KB | Output is correct |
2 | Correct | 25 ms | 748 KB | Output is correct |
3 | Correct | 24 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 876 KB | Output is correct |
2 | Correct | 2 ms | 1004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 2924 KB | Output is correct |
2 | Correct | 31 ms | 2924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 3072 KB | Output is correct |
2 | Correct | 37 ms | 3052 KB | Output is correct |
3 | Correct | 36 ms | 3052 KB | Output is correct |
4 | Correct | 37 ms | 3052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 3948 KB | Output is correct |
2 | Correct | 44 ms | 3948 KB | Output is correct |
3 | Correct | 46 ms | 4076 KB | Output is correct |
4 | Correct | 46 ms | 3948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |