# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
499920 |
2021-12-30T04:09:41 Z |
gozonite |
Pairs (IOI07_pairs) |
C++14 |
|
1094 ms |
9184 KB |
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
using namespace std;
using ll = long long;
struct vert {
int x, y, t;
};
bool cmp(const vert& a, const vert& b) {
if (a.x != b.x) return a.x < b.x;
return a.t < b.t;
}
int B, N, D, M;
int inp[3][100001];
// B = 2
vert verts[200001];
int bit1[150002]={};
void addv(int k, int v) {
for(; k <= 150000; k += k&-k) bit1[k] += v;
}
int sumr(int k) {
int s = 0;
for (; k >= 1; k -= k&-k) s += bit1[k];
return s;
}
// B = 3
int bit2[76][151][151]={};
void addv(int x, int y, int z, int v) {
for (int i = x; i <= 150; i += i&-i)
for (int j = y; j <= 150; j += j&-j) bit2[z][i][j] += v;
}
int sumr(int x, int y, int z) {
int s = 0;
for (int i = x; i >= 1; i -= i&-i)
for (int j = y; j >= 1; j -= j&-j) s += bit2[z][i][j];
return s;
}
int sumr(int fx, int fy, int sx, int sy, int z) {
return sumr(sx, sy, z) - sumr(sx, fy-1, z) - sumr(fx-1, sy, z) + sumr(fx-1, fy-1, z);
}
int main() {
cin >> B >> N >> D >> M;
if (B==1) {
for (int i = 1; i <= N; i++) cin >> inp[0][i];
sort(inp[0]+1, inp[0]+1+N);
int idx = 1;
ll cnt = 0;
for (int i = 1; i <= N; i++) {
while (idx < N && inp[0][i]+D >= inp[0][idx+1]) idx++;
cnt += (idx-i);
}
cout << cnt << endl;
} else if (B==2) {
for (int i = 1; i <= N; i++) cin >> inp[0][i] >> inp[1][i];
for (int i = 1; i <= N; i++) {
verts[2*i-1] = {inp[0][i]-inp[1][i], inp[0][i]+inp[1][i], 0};
verts[2*i] = {inp[0][i]-inp[1][i]+D, inp[0][i]+inp[1][i], 1};
}
sort(verts+1, verts+1+2*N, cmp);
ll ans = 0;
for (int i = 1; i <= 2*N; i++) {
int y = verts[i].y;
if (verts[i].t == 0) {
int fy = max(2, y-D), sy = min(2*M, y+D);
ans += sumr(sy)-sumr(fy-1);
addv(y, 1);
} else {
addv(y, -1);
}
}
cout << ans << endl;
} else if (B==3) {
for (int i = 1; i <= N; i++) cin >> inp[0][i] >> inp[1][i] >> inp[2][i];
ll ans = 0;
for (int i = 1; i <= N; i++) {
int x = inp[0][i], y = inp[1][i], z = inp[2][i];
for (int h = 1; h <= M; h++) {
if (abs(h-z) > D) continue;
int d = D-abs(h-z);
int fx = max(1, x-y+75-d), sx = min(150, x-y+75+d);
int fy = max(1, x+y-d), sy = min(150, x+y+d);
ans += sumr(fx, fy, sx, sy, h);
}
addv(x-y+75, x+y, z, 1);
}
cout << ans << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
684 KB |
Output is correct |
2 |
Correct |
28 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
568 KB |
Output is correct |
2 |
Correct |
43 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
572 KB |
Output is correct |
2 |
Correct |
42 ms |
672 KB |
Output is correct |
3 |
Correct |
39 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
844 KB |
Output is correct |
2 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
3408 KB |
Output is correct |
2 |
Correct |
56 ms |
3400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
3360 KB |
Output is correct |
2 |
Correct |
65 ms |
3448 KB |
Output is correct |
3 |
Correct |
64 ms |
3360 KB |
Output is correct |
4 |
Correct |
62 ms |
3400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
3908 KB |
Output is correct |
2 |
Correct |
78 ms |
3908 KB |
Output is correct |
3 |
Correct |
74 ms |
3872 KB |
Output is correct |
4 |
Correct |
82 ms |
3880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4544 KB |
Output is correct |
2 |
Correct |
8 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
1660 KB |
Output is correct |
2 |
Correct |
124 ms |
2224 KB |
Output is correct |
3 |
Correct |
96 ms |
2268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
6200 KB |
Output is correct |
2 |
Correct |
802 ms |
7088 KB |
Output is correct |
3 |
Correct |
193 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
799 ms |
8356 KB |
Output is correct |
2 |
Correct |
1094 ms |
9184 KB |
Output is correct |
3 |
Correct |
255 ms |
8976 KB |
Output is correct |