# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
298759 | 2020-09-14T00:47:27 Z | Hemimor | Pairs (IOI07_pairs) | C++14 | 3406 ms | 4472 KB |
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <vector> #include <cmath> #include <queue> #include <set> #include <map> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P,int> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; class Segment_Tree{ private: int n; vi date; public: Segment_Tree(int n_){ n=1; while(n<n_) n*=2; date=vi(2*n-1); } void Update(int k,int x){ k+=n-1; date[k]+=x; while(k>0){ k=(k-1)/2; date[k]=date[k*2+1]+date[k*2+2]; } } int Query(int a,int b){ a+=n-1;b+=n-1; int m=0; while(a<b){ if(a%2==0) m+=date[a++]; if(b%2==0) m+=date[--b]; a/=2;b/=2; } return m; } int Open(int k){return date[k+n-1];} }; const int M=76; int tp,n,d,mx; ll res=0; int main(){ scanf("%d%d%d%d",&tp,&n,&d,&mx); if(tp==1){ vi a(n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a.begin(),a.end()); int I=0; for(int i=0;i<n;i++){ while(a[i]-a[I]>d) I++; res+=i-I; } } if(tp==2){ vp a(n); for(int i=0;i<n;i++){ int x,y; scanf("%d%d",&x,&y); a[i]=make_pair(x-y,x+y); } sort(a.begin(),a.end()); Segment_Tree st(200000); int I=0; for(auto p:a){ int x=p.first,y=p.second; while(x-a[I].first>d) st.Update(a[I++].second,-1); res+=st.Query(y-d,y+d+1); st.Update(y,1); } } if(tp==3){ int a[M][M][M],b[M][M][M]; for(int i=0;i<M;i++) for(int j=0;j<M;j++) for(int k=0;k<M;k++) a[i][j][k]=b[i][j][k]=0; for(int i=0;i<n;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); a[x][y][z]++; b[x][y][z]++; } for(int i=0;i<M;i++) for(int j=0;j<M;j++) for(int k=1;k<M;k++) b[i][j][k]+=b[i][j][k-1]; for(int i=0;i<M;i++) for(int j=0;j<M;j++) for(int k=0;k<M;k++) if(a[i][j][k]){ ll tmp=-1; for(int I=0;I<M;I++) for(int J=0;J<M;J++){ int t=abs(I-i)+abs(J-j); if(t<=d){ tmp+=b[I][J][min(M-1,k+d-t)]-b[I][J][max(0,k-d+t-1)]; } } res+=tmp*a[i][j][k]; } res/=2; } printf("%lld\n",res); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 1024 KB | Output is correct |
2 | Correct | 19 ms | 1024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 1024 KB | Output is correct |
2 | Correct | 25 ms | 1024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 1024 KB | Output is correct |
2 | Correct | 25 ms | 1024 KB | Output is correct |
3 | Correct | 23 ms | 1024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2432 KB | Output is correct |
2 | Correct | 3 ms | 2432 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 3704 KB | Output is correct |
2 | Correct | 43 ms | 3712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 3964 KB | Output is correct |
2 | Correct | 50 ms | 3960 KB | Output is correct |
3 | Correct | 50 ms | 4096 KB | Output is correct |
4 | Correct | 49 ms | 4088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 4472 KB | Output is correct |
2 | Correct | 64 ms | 4472 KB | Output is correct |
3 | Correct | 55 ms | 4344 KB | Output is correct |
4 | Correct | 53 ms | 4216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 3712 KB | Output is correct |
2 | Correct | 42 ms | 3840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 3968 KB | Output is correct |
2 | Correct | 40 ms | 4096 KB | Output is correct |
3 | Correct | 41 ms | 3712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 676 ms | 3796 KB | Output is correct |
2 | Correct | 2039 ms | 3712 KB | Output is correct |
3 | Correct | 2769 ms | 3712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1343 ms | 3712 KB | Output is correct |
2 | Correct | 3285 ms | 3796 KB | Output is correct |
3 | Correct | 3406 ms | 3796 KB | Output is correct |