# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54552 |
2018-07-04T05:11:25 Z |
노영훈(#1490) |
Pairs (IOI07_pairs) |
C++11 |
|
4000 ms |
3840 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;
int b,n,d,m;
ll ans=0;
void solve1(){
int A[MX];
for(int i=1; i<=n; i++) cin>>A[i];
sort(A+1, A+n+1);
for(int i=1, r=1; i<=n; i++){
while(r<n && A[r+1]<=A[i]+d) r++;
ans+=r-i;
}
}
struct _SEG {
int tree[150000*4], n;
void init(int sz){
n=sz;
for(int i=1; i<150000*4; i++) tree[i]=0;
}
void upt(int v, int s, int e, int pos, int val){
if(pos<s || e<pos) return;
tree[v]+=val;
if(s==e) return;
upt(v*2,s,(s+e)/2,pos,val);
upt(v*2+1,(s+e)/2+1,e,pos,val);
}
int sum(int v, int s, int e, int l, int r){
if(e<l || r<s) return 0;
if(l<=s && e<=r) return tree[v];
return sum(v*2,s,(s+e)/2,l,r) + sum(v*2+1,(s+e)/2+1,e,l,r);
}
void upt(int pos, int val){
upt(1,1,n,pos,val);
}
int sum(int l, int r){
l=max(l,1);
r=min(r,n);
if(r<l) return 0;
return sum(1,1,n,l,r);
}
};
struct pt2 {
int x, y;
bool operator < (const pt2 &p) const {
return x-y<p.x-p.y;
}
void scan(){
cin>>x>>y;
}
};
void solve2(){
_SEG Seg; Seg.init(150000);
pt2 P[MX];
for(int i=1; i<=n; i++) P[i].scan();
sort(P+1, P+n+1);
for(int i=1, r=0, l=1; i<=n; i++){
while(r<n && P[r+1].x-P[r+1].y<=P[i].x-P[i].y+d){
r++;
Seg.upt(P[r].x+P[r].y,1);
}
while(l<=i){
Seg.upt(P[l].x+P[l].y,-1);
l++;
}
ans+=Seg.sum(P[i].x+P[i].y-d, P[i].x+P[i].y+d);
}
}
struct pt3 {
int x, y, z;
void scan(){
cin>>x>>y>>z;
}
int f(){
return x+y+z;
}
bool operator < (const pt3 &p) const {
return x+y+z<p.x+p.y+p.z;
}
bool hit(const pt3 &p){
return abs(x-p.x)+abs(y-p.y)+abs(z-p.z)<=d;
}
};
void solve3(){
pt3 P[MX];
for(int i=1; i<=n; i++) P[i].scan();
sort(P+1, P+n+1);
for(int i=1; i<=n; i++){
for(int j=i+1; j<=n; j++){
if(P[j].f()>P[i].f()+d) break;
if(P[i].hit(P[j])) ans++;
}
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>b>>n>>d>>m;
if(b==1) solve1();
if(b==2) solve2();
if(b==3) solve3();
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
904 KB |
Output is correct |
2 |
Correct |
16 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1080 KB |
Output is correct |
2 |
Correct |
23 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1080 KB |
Output is correct |
2 |
Correct |
23 ms |
1080 KB |
Output is correct |
3 |
Correct |
22 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2924 KB |
Output is correct |
2 |
Correct |
5 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
3692 KB |
Output is correct |
2 |
Correct |
61 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
3840 KB |
Output is correct |
2 |
Correct |
81 ms |
3840 KB |
Output is correct |
3 |
Correct |
92 ms |
3840 KB |
Output is correct |
4 |
Correct |
75 ms |
3840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
3840 KB |
Output is correct |
2 |
Correct |
117 ms |
3840 KB |
Output is correct |
3 |
Correct |
101 ms |
3840 KB |
Output is correct |
4 |
Correct |
80 ms |
3840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3840 KB |
Output is correct |
2 |
Correct |
4 ms |
3840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3591 ms |
3840 KB |
Output is correct |
2 |
Execution timed out |
4022 ms |
3840 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3960 ms |
3840 KB |
Output is correct |
2 |
Execution timed out |
4038 ms |
3840 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4045 ms |
3840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |