19202022-12-10 17:29:45KovácsHunorForma-1cpp11Runtime error 0/1002.086s5716 KiB
#include "stdio.h"
#include "stdlib.h"

long long compare(const void* a, const void* b){
    return *(long long*)a-*(long long*)b;
}

void QuickSort(long long* arr, long long* index, long long size){
    long long pivot = 0;
    for (long long i = 1; i < size; i++)
    {
        if(arr[pivot] < arr[i] || (arr[pivot] == arr[i] && index[pivot] > index[i])){
            arr[pivot] ^= arr[pivot+1];
            arr[pivot+1] ^= arr[pivot];
            arr[pivot] ^= arr[pivot+1];

            index[pivot] ^= index[pivot+1];
            index[pivot+1] ^= index[pivot];
            index[pivot] ^= index[pivot+1];
            pivot++;

            if(i != pivot){
                arr[pivot-1] ^= arr[i];
                arr[i] ^= arr[pivot-1];
                arr[pivot-1] ^= arr[i];

                index[pivot-1] ^= index[i];
                index[i] ^= index[pivot-1];
                index[pivot-1] ^= index[i];
            }
        }
    }
    if(pivot > 1)        QuickSort(arr, index, pivot);
    if(pivot < size-2) QuickSort(arr + (pivot+1), index + (pivot+1), size - (pivot+1));
}

long long distance(long long a, long long b, long long c, long long t){
    return t*t*a + t*b + c;
}

int main()
{
    long long n, q;
    scanf("%lld", &n);
    long long* arr = (long long*)malloc(sizeof(long long)*n*3);
    for (long long i = 0; i < n; i++)
    {
        scanf("%lld%lld%lld", arr + i, arr + i + n, arr + i + 2*n);
    }
    scanf("%lld", &q);
    long long* sol = (long long*)malloc(sizeof(long long)*q);
    long long* dis = (long long*)malloc(sizeof(long long)*n);
    long long* index = (long long*)malloc(sizeof(long long)*n);

    for (long long i = 0; i < q; i++)
    {
        long long p, t;
        scanf("%lld%lld", &p, &t);


        for (long long j = 0; j < n; j++)
        {
            index[j] = j+1;
        }
        for (long long j = 0; j < n; j++)
        {
            dis[j] = distance(arr[j], arr[j+n], arr[j+2*n], t);
        }

        QuickSort(dis, index, n);
        sol[i] = index[p-1];
    }
    for (long long i = 0; i < q; i++)
    {
        printf("%lld\n", sol[i]);
    }
    free(arr);
    free(sol);
    free(dis);
    return 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1364 KiB
subtask20/20
2Runtime error83ms4468 KiB
3Runtime error87ms4616 KiB
4Runtime error83ms4836 KiB
5Runtime error81ms5052 KiB
6Runtime error86ms5240 KiB
7Runtime error82ms5444 KiB
8Runtime error82ms5640 KiB
9Runtime error81ms5716 KiB
subtask30/30
10Time limit exceeded2.068s2856 KiB
11Time limit exceeded2.015s3028 KiB
12Time limit exceeded2.062s3124 KiB
13Time limit exceeded2.052s3064 KiB
14Time limit exceeded2.061s3056 KiB
15Time limit exceeded2.065s3404 KiB
16Time limit exceeded2.055s3148 KiB
17Time limit exceeded2.056s3444 KiB
18Time limit exceeded2.049s3196 KiB
subtask40/50
19Time limit exceeded2.052s3668 KiB
20Time limit exceeded2.052s3548 KiB
21Time limit exceeded2.052s3812 KiB
22Time limit exceeded2.056s3432 KiB
23Time limit exceeded2.025s3448 KiB
24Time limit exceeded2.046s3428 KiB
25Time limit exceeded2.052s3816 KiB
26Time limit exceeded2.046s3996 KiB
27Time limit exceeded2.058s3976 KiB
28Time limit exceeded2.086s3936 KiB
29Time limit exceeded2.016s3836 KiB
30Time limit exceeded2.013s4436 KiB