Submission #786474

#TimeUsernameProblemLanguageResultExecution timeMemory
786474danikoynovPairs (IOI07_pairs)C++14
45 / 100
56 ms5836 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 1e5 + 10; struct point { int x, y, z; point(int _x = 0, int _y = 0, int _z = 0) { x = _x; y = _y; z = _z; } } p[maxn], s[maxn]; bool cmp(point p1, point p2) { if (p1.x != p2.x) return p1.x < p2.x; if (p1.y != p2.y) return p1.y < p2.y; return p1.z < p2.z; } const int max_size = 75010; struct fenwick_1d { int fen[max_size]; void update(int pos, int val) { for (int i = pos; i < max_size; i += (i & -i)) fen[i] += val; } int query(int pos) { if (pos > max_size) pos = max_size - 1; if (pos < 0) pos = 0; int s = 0; for (int i = pos; i > 0; i -= (i & -i)) s += fen[i]; return s; } }; int b, n, d, m; void solve() { cin >> b >> n >> d >> m; for (int i = 1; i <= n; i ++) { cin >> p[i].x; if (b >= 2) cin >> p[i].y; if (b == 3) cin >> p[i].z; } if (b == 1) { sort(p + 1, p + n + 1, cmp); int pt = 1; ll ans = 0; for (int i = 1; i <= n; i ++) { while(p[i].x - p[pt].x > d) pt ++; ///cout << i << " : " << p[i].x << " " << pt << endl; ans += (ll)(i - pt); } cout << ans << endl; } else if (b == 2) { for (int i = 1; i <= n; i ++) { s[i].x = p[i].x - p[i].y; s[i].y = p[i].x + p[i].y; } ll ans = 0; /**for (int i = 1; i <= n; i ++) for (int j = i + 1; j <= n; j ++) if (abs(s[i].x - s[j].x) <= d && abs(s[i].y - s[j].y) <= d) ans ++;*/ fenwick_1d tree; sort(s + 1, s + n + 1, cmp); int pt = 1; for (int i = 1; i <= n; i ++) { tree.update(s[i].y, 1); while(s[i].x - s[pt].x > d) { tree.update(s[pt].y, -1); pt ++; } ll len = tree.query(s[i].y + d) - tree.query(s[i].y - d - 1); ans = ans + (len - 1); } cout << ans << endl; } else { assert(false); } } int main() { solve(); 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...