Submission #157617

# Submission time Handle Problem Language Result Execution time Memory
157617 2019-10-12T15:27:54 Z stefdasca Pairs (IOI07_pairs) C++14
47 / 100
36 ms 3448 KB
#include<bits/stdc++.h>
using namespace std;
int tip, n, d, m;
long long ans;


struct tp
{
    int x, y, z;
};
tp vv[10002];
void solvesmall()
{
    for(int i = 1; i <= n; ++i)
    {
        cin >> vv[i].x;
        if(tip >= 2)
            cin >> vv[i].y;
        if(tip >= 3)
            cin >> vv[i].z;
    }
    for(int i = 1; i <= n; ++i)
        for(int j = i+1; j <= n; ++j)
        {
            int dd = abs(vv[i].x - vv[j].x) + abs(vv[i].y - vv[j].y) + abs(vv[i].z - vv[j].z);
            if(dd <= d)
                ++ans;
        }
    cout << ans << '\n';
}

int v[100002];
void solve1()
{
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    sort(v+1, v+n+1);
    for(int i = 1; i <= n; ++i)
    {
        int sm = i;
        int st = 1;
        int dr = i-1;
        while(st <= dr)
        {
            int mid = (st + dr) / 2;
            if(v[i] - v[mid] <= d)
                sm = mid, dr = mid - 1;
            else
                st = mid + 1;
        }
        ans += (i - sm);
    }
    cout << ans << '\n';
}
int aib[322][200002];
vector<int>coord[100002];
pair<int, int> nr[100002];
void upd(int zona, int pozitie)
{
    for(; pozitie <= 200000; pozitie += (pozitie & (-pozitie)))
        aib[zona][pozitie]++;
}
int query(int zona, int pozitie)
{
    int ans = 0;
    for(; pozitie <= 200000; pozitie -= (pozitie & (-pozitie)))
        ans += aib[zona][pozitie];
    return ans;
}
void solve2()
{
    for(int i = 1; i <= n; ++i)
        cin >> nr[i].first >> nr[i].second, nr[i].second += 100000;
    sort(nr + 1, nr + n + 1);
}
void solve3()
{

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> tip >> n >> d >> m;
    if(n <= 10000)
        solvesmall();
    else
        if(tip == 1)
            solve1();
        else
            if(tip == 2)
                solve2();
            else
                if(tip == 3)
                    solve3();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3064 KB Output is correct
2 Correct 23 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3064 KB Output is correct
2 Correct 29 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3064 KB Output is correct
2 Correct 33 ms 3096 KB Output is correct
3 Correct 32 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -