# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
94734 |
2019-01-23T12:24:08 Z |
SuperJava |
Pairs (IOI07_pairs) |
C++17 |
|
410 ms |
525312 KB |
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define N (100'005)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)
//vector<pair<ll,ll>> base;
vector<pair<int,int>> bs[80];
//vector<ll> seg[N*4];
vector<int> segi[80][N*4];
/*
void build(int n,int l,int r){
if(l == r){
seg[n].push_back(base[l].first-base[l].second);
return;
}
int mid = (l+r)/2;
build(2*n,l,mid);
build(2*n+1,mid+1,r);
seg[n] = seg[2*n];
seg[n].insert(seg[n].end(),seg[2*n+1].begin(),seg[2*n+1].end());
sort(seg[n].begin(), seg[n].end());
}
ll get(int n,int l,int r,ll x,ll e,ll q,ll w){
if(l > e || r < x) return 0;
if(x <= l && r <= e)
return upper_bound(seg[n].begin(), seg[n].end(), w) -
lower_bound(seg[n].begin(), seg[n].end(), q);
ll mid = (l+r)/2;
return get(2*n,l,mid,x,e,q,w)+get(2*n+1,mid+1,r,x,e,q,w);
}
*/
void buildi(int i,int n,int l,int r){
if(l == r){
segi[i][n].push_back(bs[i][l].first-bs[i][l].second);
return;
}
int mid = (l+r)/2;
buildi(i,2*n,l,mid);
buildi(i,2*n+1,mid+1,r);
segi[i][n] = segi[i][2*n];
segi[i][n].insert(segi[i][n].end(),segi[i][2*n+1].begin(),segi[i][2*n+1].end());
sort(segi[i][n].begin(), segi[i][n].end());
}
int geti(int i,int n,int l,int r,int x,int e,int q,int w){
if(l > e || r < x) return 0;
if(x <= l && r <= e)
return upper_bound(segi[i][n].begin(), segi[i][n].end(), w) -
lower_bound(segi[i][n].begin(), segi[i][n].end(), q);
int mid = (l+r)/2;
return geti(i,2*n,l,mid,x,e,q,w)+geti(i,2*n+1,mid+1,r,x,e,q,w);
}
int main(){
//fold
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cout << setprecision(10);
//endfold
int b,n,d,m;
cin >> b >> n >> d >> m;
if(b == 1){
/*vector<ll> v;
rep(i,0,n){
ll w;
cin >> w;
v.push_back(w);
}
sort(v.begin(), v.end());
ll ans = 0;
rep(i,0,n){
ans += upper_bound(v.begin(), v.end(),v[i]+d)-lower_bound(v.begin(), v.end(),v[i]-d)-1;
}
cout << ans/2;*/
}else if(b == 2){
/*vector<ll> z;
rep(i,0,n){
ll w,q;
cin >> q >> w;
base.push_back({q,w});
z.push_back(q+w);
}
sort(z.begin(), z.end());
sort(base.begin(), base.end(),
[](pair<int,int> a,pair<int,int> b){
return a.first+a.second < b.first+b.second;
});
build(1,0,n-1);
ll ans = 0;
rep(i,0,n){
ll l = lower_bound(z.begin(), z.end(),z[i]-d)-z.begin();
ll r = upper_bound(z.begin(), z.end(),z[i]+d)-z.begin()-1;
ans += get(1,0,n-1,l,r,base[i].first-d-base[i].second,
base[i].first+d-base[i].second);
}
cout << (ans-n)/2 << endl;*/
}else{
d = min(d,75*3);
vector<tuple<int,int,int>> v;
vector<vector<int>> z(80);
rep(i,0,n){
ll w,q,e;
cin >> q >> w >> e;
v.push_back({q,w,e});
z[q].push_back(w+e);
bs[q].push_back({w,e});
}
sort(v.begin(), v.end());
rep(i,1,76){
sort(z[i].begin(), z[i].end());
}
rep(i,1,76){
sort(bs[i].begin(), bs[i].end(),
[](pair<int,int> a,pair<int,int> b){
return a.first+a.second < b.first+b.second;
});
}
rep(i,1,75){
if(sz(z[i]))
buildi(10,1,0,sz(z[i])-1);
}
ll ans = 0;
rep(i,0,n){
int x,y,p;
tie(x,y,p) = v[i];
for (int j = max(1,x-d); j <= min(x+d,75); ++j){
int dist = abs(j-x);
int l = lower_bound(z[j].begin(), z[j].end(),y+p-(d-dist))-z[j].begin();
int r = upper_bound(z[j].begin(), z[j].end(),y+p+(d-dist))-z[j].begin()-1;
if(l <= r && l != sz(z[j])){
ans += geti(j,1,0,sz(z[j])-1,l,r,y-(d-dist)-p,y+(d-dist)-p);
}
}
}
cout << (ans-n)/2;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
366 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
376 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
383 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
371 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
402 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
410 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
371 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
408 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
366 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
392 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |