#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
namespace Subtask1{
vector<int> v;
int getsum(int x, int y, int m){
int result = 0;
if(y <= m)
result += v[y];
else
result += v[m];
if(0 < x)
result -= v[x - 1];
return result;
}
void solve(){
int n, d, m;
cin >> n >> d >> m;
v.resize(1 + m);
for(int i = 1;i <= n; i++){
int x;
cin >> x;
v[x]++;
}
for(int i = 1;i <= m; i++)
v[i] += v[i - 1];
ll result = 0;
for(int i = 1;i <= m; i++)
if(0 < v[i] - v[i - 1])
result += (v[i] - v[i - 1]) * getsum(i - d, i + d, m);
result -= n;
cout << result / 2 << '\n';
}
}
namespace Subtask2{
int const nmax = 200000;
class FenwickTree{
private:
int n;
vector<int> aib;
public:
FenwickTree(int n){
this->n = n;
aib.resize(1 + n);
}
void update(int x, int val){
while(x <= n){
aib[x] += val;
x += (x ^ (x & (x - 1)));
}
}
int query(int x){
int result = 0;
while(0 < x){
result += aib[x];
x = (x & (x - 1));
}
return result;
}
};
struct Point{
int x;
int y;
bool operator < (Point const &a) const{
if(x != a.x)
return x < a.x;
else
return y < a.y;
}
} v[1 + nmax];
void solve(){
int n, d, m;
cin >> n >> d >> m;
for(int i = 1;i <= n; i++){
int x, y;
cin >> x >> y;
v[i] = {x + y - 1, x - y + m};
}
sort(v + 1, v + n + 1);
ll result = 0;
int ptr = 1;
FenwickTree aib(2 * m);
for(int i = 1;i <= n; i++){
aib.update(v[i].y, 1);
while(v[ptr].x + d < v[i].x){
aib.update(v[ptr].y, -1);
ptr++;
}
result += aib.query(MIN(2 * m, v[i].y + d)) - aib.query(MAX(0, v[i].y - d - 1));
}
cout << result - n;
}
}
namespace Subtask3{
int const nmax = 150;
int v[1 + nmax][1 + nmax][1 + nmax];
int sum[1 + nmax][1 + nmax][1 + nmax];
int getsum(int level, int x, int y, int x2, int y2, int m){
x = MAX(x, 0);
y = MAX(y, 0);
x2 = MIN(x2, m);
y2 = MIN(y2, m);
return sum[level][x2][y2] - sum[level][x - 1][y2] - sum[level][x2][y - 1] + sum[level][x - 1][y - 1];
}
void solve(){
int n, d, m;
cin >> n >> d >> m;
for(int i = 1;i <= n; i++){
int level, x, y;
cin >> level >> x >> y;
int x2 = x + y - 1, y2 = x - y + m;
v[level][x2][y2]++;
}
int lim = 2 * m;
for(int level = 1;level <= m; level++)
for(int i = 1;i <= lim; i++)
for(int j = 1;j <= lim; j++)
sum[level][i][j] = sum[level][i - 1][j] + sum[level][i][j - 1] - sum[level][i - 1][j - 1] + v[level][i][j];
ll result = 0;
for(int level = 1; level <= m; level++){
for(int i = 1;i <= lim; i++)
for(int j = 1;j <= lim; j++)
if(0 < v[level][i][j])
for(int level2 = 1; level2 <= m; level2++){
int newd = d - fabs(level2 - level);
if(0 <= newd) {
result += v[level][i][j] * getsum(level2, i - newd, j - newd, i + newd, j + newd, lim);
}
}
}
cout << (result - n) / 2;
}
}
int main()
{
int type;
cin >> type;
if(type == 1)
Subtask1::solve();
else if(type == 2)
Subtask2::solve();
else if(type == 3)
Subtask3::solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
521 ms |
293956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
632 KB |
Output is correct |
2 |
Correct |
38 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
605 ms |
275212 KB |
Output is correct |
2 |
Correct |
579 ms |
275404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
589 ms |
275280 KB |
Output is correct |
2 |
Correct |
559 ms |
275292 KB |
Output is correct |
3 |
Correct |
565 ms |
275320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
888 KB |
Output is correct |
2 |
Correct |
4 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
1656 KB |
Output is correct |
2 |
Correct |
76 ms |
1676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
1912 KB |
Output is correct |
2 |
Correct |
91 ms |
1912 KB |
Output is correct |
3 |
Correct |
91 ms |
1892 KB |
Output is correct |
4 |
Correct |
90 ms |
1856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
2784 KB |
Output is correct |
2 |
Correct |
123 ms |
2816 KB |
Output is correct |
3 |
Correct |
120 ms |
2876 KB |
Output is correct |
4 |
Correct |
117 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
9768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
1272 KB |
Output is correct |
2 |
Correct |
79 ms |
1528 KB |
Output is correct |
3 |
Correct |
78 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
9976 KB |
Output is correct |
2 |
Correct |
162 ms |
10220 KB |
Output is correct |
3 |
Correct |
152 ms |
10092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
220 ms |
14540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |