제출 #94726

#제출 시각아이디문제언어결과실행 시간메모리
94726SuperJavaPairs (IOI07_pairs)C++17
80 / 100
4030 ms31080 KiB
//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<ll> seg[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); } ll u[80][80][80]; int main(){ //fold ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(10); //endfold ll 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{ vector<tuple<ll,ll,ll>> v; rep(i,0,n){ ll w,q,e; cin >> q >> w >> e; v.push_back({q,w,e}); u[q][w][e]++; } sort(v.begin(), v.end()); if(n <= 1000){ ll ans = 0; rep(i,0,n){ rep(j,i+1,n){ ll q1,w1,e1; ll q2,w2,e2; tie(q1,w1,e1) = v[i]; tie(q2,w2,e2) = v[j]; if(abs(q1-q2)+abs(w2-w1)+abs(e2-e1) <= d) ans++; if(abs(q1-q2) > d) break; } } cout << ans; }else{ ll ans = 0; rep(i,0,n){ int x,y,z; tie(x,y,z) = v[i]; for (int j = max(1ll,x-d); j <= min(x+d,75ll); ++j){ int dist = abs(j-x); for (int k = max(1ll,y-d+dist); k <= min(y+d-dist,75ll); ++k){ int dist2 = dist + abs(k-y); for (int l = max(1ll,z-d+dist2); l <= min(z+d-dist2,75ll); ++l){ ans += u[j][k][l]; } } } } cout << (ans-n)/2; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...