답안 #53997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53997 2018-07-02T07:36:42 Z Costin Andrei Oncescu(#1302) Pairs (IOI07_pairs) C++11
30 / 100
47 ms 1900 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 < 0) 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:38: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:42:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &x[i]);
         ~~~~~~^~~~~~~~~~~~~
pairs.cpp:60:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d %d", &a, &b);
         ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 848 KB Output is correct
2 Correct 19 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 892 KB Output is correct
2 Correct 27 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 892 KB Output is correct
2 Correct 27 ms 892 KB Output is correct
3 Correct 26 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1084 KB Output is correct
2 Incorrect 3 ms 1084 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1364 KB Output is correct
2 Incorrect 37 ms 1388 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -