Submission #53998

# Submission time Handle Problem Language Result Execution time Memory
53998 2018-07-02T07:38:12 Z Costin Andrei Oncescu(#1302) Pairs (IOI07_pairs) C++11
60 / 100
58 ms 2020 KB
#include<bits/stdc++.h>

using namespace std;

int B, N, D, M, x[100009], y[100009], z[100009];
pair < int, int > v[100009];

int aibSZ, aib[150009];
void update (int pos, int val)
{
    while (pos <= aibSZ)
        aib[pos] += val,
        pos += pos - (pos & (pos - 1));
}

int query (int pos)
{
    int ans = 0;
    while (pos)
        ans += aib[pos],
        pos &= pos - 1;
    return ans;
}

int query (int l, int r)
{
    if (r > aibSZ)
        r = aibSZ;
    if (r < 0 || r < l) return 0;
    int ans = query (r);
    if (l > 0) ans -= query (l - 1);
    return ans;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &B, &N, &D, &M);
if (B == 1)
{
    for (int i=1; i<=N; i++)
        scanf ("%d", &x[i]);
    sort (x + 1, x + N + 1);
    long long ans = 1LL * N * (N - 1) / 2;
    int j = 0;
    for (int i=1; i<=N; i++)
    {
        while (x[i] - x[j + 1] > D)
            j ++;
        ans -= j;
    }
    printf ("%lld\n", ans);
    return 0;
}
if (B == 2)
{
    for (int i=1; i<=N; i++)
    {
        int a, b;
        scanf ("%d %d", &a, &b);
        v[i] = {a - b, a + b};
    }
    sort (v + 1, v + N + 1), aibSZ = 2 * M;
    int j = 1;
    long long ans = 0;
    update (v[1].second, +1);
    for (int i=2; i<=N; i++)
    {
        while (v[i].first - v[j].first > D)
            update (v[j].second, -1), j ++;
        ans += query (v[i].second - D, v[i].second + D);
        update (v[i].second, +1);
    }
    printf ("%lld\n", ans);
    return 0;
}
return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d %d %d", &B, &N, &D, &M);
 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:44:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &x[i]);
         ~~~~~~^~~~~~~~~~~~~
pairs.cpp:62:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d %d", &a, &b);
         ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 884 KB Output is correct
2 Correct 19 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 980 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 980 KB Output is correct
2 Correct 35 ms 980 KB Output is correct
3 Correct 27 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1108 KB Output is correct
2 Correct 4 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1380 KB Output is correct
2 Correct 33 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 1404 KB Output is correct
2 Correct 39 ms 1404 KB Output is correct
3 Correct 45 ms 1404 KB Output is correct
4 Correct 42 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1892 KB Output is correct
2 Correct 54 ms 2020 KB Output is correct
3 Correct 52 ms 2020 KB Output is correct
4 Correct 50 ms 2020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -