# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
522000 |
2022-02-03T15:09:09 Z |
emanuelsilva |
Pairs (IOI07_pairs) |
C++17 |
|
414 ms |
122328 KB |
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
const int MAX = 4*76;
const int SHIFT = 76;
struct bit {
int n;
vector<int> b;
bit() {}
bit(int n_) : n(n_) {
b.resize(n_+1);
}
void poe(int x, int val) { for (; x <= n; x += x & -x) b[x] += val; }
int pref(int x) {
if (x <= 0) return 0;
int ret = 0;
for (; x; x -= x & -x) ret += b[x];
return ret;
}
int query(int x0, int x1) { return pref(x1) - pref(x0-1); }
};
struct bit2d {
int n;
vector<bit> b;
bit2d() {}
bit2d(int n_) : n(n_) {
b.resize(n_+1, n_+1);
}
void poe(int x, int y, int val) { for (; x <= n; x += x & -x) b[x].poe(y, val); }
int pref(int x, int y) {
if (x <= 0 or y <= 0) return 0;
int ret = 0;
for (; x; x -= x & -x) ret += b[x].pref(y);
return ret;
}
int query(int x0, int y0, int x1, int y1) {
return pref(x1, y1) - pref(x1, y0-1) - pref(x0-1, y1) + pref(x0-1, y0-1);
}
};
struct bit3d {
int n;
vector<bit2d> b;
bit3d() {}
bit3d(int n_) : n(n_) {
b.resize(n_+1, n_+1);
}
void poe(int x, int y, int z, int val) { for (; x <= n; x += x & -x) b[x].poe(y, z, val); }
int pref(int x, int y, int z) {
if (x <= 0 or y <= 0 or z <= 0) return 0;
x = min(x, n), y = min(y, n), z = min(z, n);
int ret = 0;
for (; x; x -= x & -x) ret += b[x].pref(y, z);
return ret;
}
int query(int x0, int y0, int z0, int x1, int y1, int z1) {
return pref(x1, y1, z1)
- pref(x1, y1, z0-1) - pref(x1, y0-1, z1) - pref(x0-1, y1, z1)
+ pref(x1, y0-1, z0-1) + pref(x0-1, y1, z0-1) + pref(x0-1, y0-1, z1)
- pref(x0-1, y0-1, z0-1);
}
};
void solve1(int n, int d, int m) {
vector<pair<int, int>> ev;
for (int i = 0; i<n; i++) {
int x; cin >> x;
ev.emplace_back(x, 0);
ev.emplace_back(x+d, 1);
}
sort(ev.begin(), ev.end());
int cnt = 0;
ll ans = 0;
for (auto [x, ty] : ev) {
if (ty == 0) ans += cnt, cnt++;
else cnt--;
}
cout << ans << endl;
}
void solve2(int n, int d, int m) {
vector<tuple<int, int, int, int>> ev;
for (int i = 0; i<n; i++) {
int x, y; cin >> x >> y;
int nx = x + y;
y = x - y;
x = nx;
ev.emplace_back(x, 0, y, i);
ev.emplace_back(x+d, 1, y, i);
}
sort(ev.begin(), ev.end());
ord_set<pair<int, int>> st;
ll ans = 0;
for (auto [x, ty, y, i] : ev) {
if (ty == 0) {
ans += st.order_of_key({y+d, INF}) - st.order_of_key({y-d, -INF});
st.insert({y, i});
}
else st.erase({y, i});
}
cout << ans << endl;
}
void solve3(int n, int d, int m) {
vector<tuple<int, int, int, int, int>> ev; // w ty x y z
for (int i = 0; i<n; i++) {
int x, y, z; cin >> x >> y >> z;
int nx = x + y + z + SHIFT;
int ny = x + y - z + SHIFT;
int nz = x - y + z + SHIFT;
int nw = x - y - z;
ev.emplace_back(nw, 0, nx, ny, nz);
ev.emplace_back(nw+d, 1, nx, ny, nz);
}
sort(ev.begin(), ev.end());
ll ans = 0;
bit3d b(MAX);
for (auto [w, ty, x, y, z] : ev) {
if (ty == 0) {
ans += b.query(x-d, y-d, z-d, x+d, y+d, z+d);
b.poe(x, y, z, +1);
}
else b.poe(x, y, z, -1);
}
cout << ans << endl;
}
int main() { _
int b, n, d, m; cin >> b >> n >> d >> m;
if (b == 1) solve1(n, d, m);
if (b == 2) solve2(n, d, m);
if (b == 3) solve3(n, d, m);
exit(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2632 KB |
Output is correct |
2 |
Correct |
20 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2632 KB |
Output is correct |
2 |
Correct |
26 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2624 KB |
Output is correct |
2 |
Correct |
37 ms |
2632 KB |
Output is correct |
3 |
Correct |
27 ms |
2556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
4656 KB |
Output is correct |
2 |
Correct |
109 ms |
9544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
4672 KB |
Output is correct |
2 |
Correct |
151 ms |
6916 KB |
Output is correct |
3 |
Correct |
123 ms |
6468 KB |
Output is correct |
4 |
Correct |
131 ms |
6164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
4676 KB |
Output is correct |
2 |
Correct |
148 ms |
6856 KB |
Output is correct |
3 |
Correct |
110 ms |
8188 KB |
Output is correct |
4 |
Correct |
101 ms |
6384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
117624 KB |
Output is correct |
2 |
Correct |
62 ms |
117544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
205 ms |
121772 KB |
Output is correct |
2 |
Correct |
181 ms |
121764 KB |
Output is correct |
3 |
Correct |
236 ms |
121668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
121772 KB |
Output is correct |
2 |
Correct |
370 ms |
121764 KB |
Output is correct |
3 |
Correct |
208 ms |
121768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
121712 KB |
Output is correct |
2 |
Correct |
414 ms |
122328 KB |
Output is correct |
3 |
Correct |
211 ms |
122276 KB |
Output is correct |