Submission #795864

# Submission time Handle Problem Language Result Execution time Memory
795864 2023-07-27T18:17:41 Z SUNWOOOOOOOO Pairs (IOI07_pairs) C++17
85 / 100
116 ms 9620 KB
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using pint = pair <int, int>;
using tint = array <int, 3>;
int b, n, d, m;
LL ans = 0;

void calc1()
{
    vector <int> A(n);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    sort(A.begin(), A.end());
    for (int i = 1, j = 0; i < n; i++){
        while (A[i] - A[j] > d) j++;
        ans += i - j;
    }
}

struct seg1D {
    int node[800000], nn = 160000;
    void update(int x, int val){
        for (x += nn - 1; x > 0; x /= 2) node[x] += val;
    }
    int query(int L, int R){
        int ret = 0;
        for (L += nn - 1, R += nn - 1; L <= R; L /= 2, R /= 2){
            if (L % 2 == 1) ret += node[L++];
            if (R % 2 == 0) ret += node[R--];
        }
        return ret;
    }
};

void calc2()
{
    vector <pint> A(n);
    for (int i = 0, x, y; i < n; i++){
        scanf("%d %d", &x, &y);
        A[i] = {x + y, x - y + 75000};
    }
    sort(A.begin(), A.end());

    seg1D tree;
    tree.update(A[0].second, 1);
    for (int i = 1, j = 0; i < n; i++){
        while (A[i].first - A[j].first > d){
            tree.update(A[j].second, -1);
            j++;
        }
        ans += tree.query(A[i].second - d, min(A[i].second + d, 150000));
        tree.update(A[i].second, 1);
    }
}

int s[80][160][160];

void calc3()
{
    vector <tint> A(n);
    for (int i = 0, x, y, z; i < n; i++){
        scanf("%d %d %d", &x, &y, &z);
        s[z][x + y][x - y + 75]++;
        A[i] = {x, y, z};
    }
    for (int z = 0; z <= 75; z++){
        for (int i = 1; i <= 150; i++){
            for (int j = 1; j <= 150; j++){
                s[z][i][j] += s[z][i - 1][j] + s[z][i][j - 1] - s[z][i - 1][j - 1];
            }
        }
    }
    for (int i = 0, d1, d2, az; i < n; i++){
        d1 = A[i][0] + A[i][1], d2 = A[i][0] - A[i][1] + 75, az = A[i][2];
        for (int j = 0; j <= 75; j++){
            int dist = d - abs(az - j);
            if (dist < 0) continue;
            ans += s[j][min(dist + d1, 150)][min(dist + d2, 150)];
            ans -= s[j][min(dist + d1, 150)][max(-dist + d2 - 1, 0)];
            ans -= s[j][max(-dist + d1 - 1, 0)][min(dist + d2, 150)];
            ans += s[j][max(-dist + d1 - 1, 0)][max(-dist + d2 - 1, 0)];
        }
        ans -= 1;
    }
    ans /= 2;
}

int main()
{
    scanf("%d %d %d %d", &b, &n, &d, &m);
    if (b == 1) calc1();
    if (b == 2) calc2();
    if (b == 3) calc3();

    printf("%lld\n", ans);

    return 0;
}

Compilation message

pairs.cpp: In function 'void calc1()':
pairs.cpp:12:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     for (int i = 0; i < n; i++) scanf("%d", &A[i]);
      |                                 ~~~~~^~~~~~~~~~~~~
pairs.cpp: In function 'void calc2()':
pairs.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void calc3()':
pairs.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d %d %d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     scanf("%d %d %d %d", &b, &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 980 KB Output is correct
2 Correct 11 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1472 KB Output is correct
2 Correct 14 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1460 KB Output is correct
2 Correct 17 ms 1492 KB Output is correct
3 Correct 14 ms 1468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Incorrect 2 ms 3412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4692 KB Output is correct
2 Correct 23 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4948 KB Output is correct
2 Correct 30 ms 4980 KB Output is correct
3 Correct 27 ms 4976 KB Output is correct
4 Correct 28 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 5332 KB Output is correct
2 Incorrect 38 ms 5372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7528 KB Output is correct
2 Correct 8 ms 7620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 9440 KB Output is correct
2 Correct 41 ms 9292 KB Output is correct
3 Correct 53 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 9604 KB Output is correct
2 Correct 116 ms 9532 KB Output is correct
3 Correct 79 ms 9540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 9620 KB Output is correct
2 Correct 113 ms 9564 KB Output is correct
3 Correct 83 ms 9552 KB Output is correct