제출 #438819

#제출 시각아이디문제언어결과실행 시간메모리
438819sinamhdvPairs (IOI07_pairs)C++11
47 / 100
4062 ms304376 KiB
// IOI07_pairs #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e9 + 100; const ll LINF = 1e18 + 100; #ifdef DEBUG #define dbg(x) cout << #x << " = " << (x) << endl << flush; #define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; } #else #define dbg(x) ; #define dbgr(s, f) ; #endif #define FOR(i, a, b) for (int i = (a); i < (int)(b); i++) #define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define fr first #define sc second #define endl '\n' #define MAXN 100100 #define MAXA 75100 const int bs = 80; int B, n, d, m; ll ans; pii pnt[MAXN]; vector<int> seg[4 * MAXN]; int ps[80][220][220]; void build(int v = 1, int l = 0, int r = n - 1) { } int get(int L, int R, int ly, int ry, int v = 1, int l = 0, int r = n - 1) { int res = 0; FOR(i, L, R + 1) if (pnt[i].sc <= ry && pnt[i].sc >= ly) res++; return res; } int32_t main(void) { fast_io; cin >> B >> n >> d >> m; if (B == 1) { vector<int> vec(m + 10); int x[MAXN] = {}; FOR(i, 0, n) { cin >> x[i]; vec[x[i]]++; } FOR(i, 1, (int)vec.size()) vec[i] += vec[i - 1]; FOR(i, 0, n) ans += vec[min(x[i] + d, m+3)] - vec[max(x[i] - d - 1, 0)]; ans -= n; ans /= 2; cout << ans << endl; return 0; } else if (B == 3) { int x[MAXN], y[MAXN], z[MAXN]; FOR(i, 0, n) { int a, b, c; cin >> a >> b >> c; x[i] = a; y[i] = b + c; z[i] = b - c; ps[x[i]][y[i]+bs][z[i]+bs]++; } FOR(i, 0, 80) { FOR(j, 1, 220) FOR(k, 1, 220) ps[i][j][k] += ps[i][j - 1][k] + ps[i][j][k - 1] - ps[i][j - 1][k - 1]; } FOR(i, 0, n) { int up = max(x[i] - d, 0); int dn = min(x[i] + d, m); dbg(i); dbg(up); dbg(dn); FOR(l, up, dn + 1) { int dis = abs(x[i] - l); d -= dis; int y1 = max(-77, y[i] - d) - 1 + bs; int y2 = min(155, y[i] + d) + bs; int z1 = max(-77, z[i] - d) - 1 + bs; int z2 = min(155, z[i] + d) + bs; ans += ps[l][y2][z2] - ps[l][y1][z2] - ps[l][y2][z1] + ps[l][y1][z1]; d += dis; } } ans -= n; ans /= 2; cout << ans << endl; return 0; } // B == 2 FOR(i, 0, n) { int x, y; cin >> x >> y; pnt[i].fr = x + y; pnt[i].sc = x - y; } sort(pnt, pnt + n); build(); // FOR(i, 0, n) // cout << "( " << pnt[i].fr << ", " << pnt[i].sc << ") "; // cout << endl; FOR(i, 0, n) { int lx = pnt[i].fr - d; int rx = pnt[i].fr + d; int ly = pnt[i].sc - d; int ry = pnt[i].sc + d; int L = lower_bound(pnt, pnt + n, mp(lx, 0)) - pnt; int R = lower_bound(pnt, pnt + n, mp(rx + 1, 0)) - pnt - 1; ans += get(L, R, ly, ry); } ans -= n; ans /= 2; cout << ans << endl; 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...