Submission #51730

# Submission time Handle Problem Language Result Execution time Memory
51730 2018-06-20T11:29:12 Z Costin Andrei Oncescu(#1294) Fortune Telling 2 (JOI14_fortune_telling2) C++11
100 / 100
266 ms 118836 KB
#include<bits/stdc++.h>

using namespace std;

int N, K, aib[200009], id[200009], A[200009], B[200009], cnt[200009];
const int INF = 1e9 + 100;
pair < int, int > h[200009];

bool cmp (int i, int j)
{
    return (min (A[i], B[i]) > min (A[j], B[j]));
}

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

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

scanf ("%d %d", &N, &K);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &A[i], &B[i]), id[i] = i;
sort (id + 1, id + N + 1, cmp);
for (int i=1; i<=K; i++)
    scanf ("%d", &h[i].first), h[i].second = i;
sort (h + 1, h + K + 1);
int j = K, lg = 0;
while ((2 << lg) <= K)
    lg ++;
for (int i=1; i<=K; i++)
    aib[i] = INF;
long long sum = 0;
for (int ii=1; ii<=N; ii++)
{
    int i = id[ii];
    while (j > 0 && h[j].first >= min (A[i], B[i]))
        update (K - h[j].second + 1, h[j].first), j --;
    int pos = 0, followingSteps = 0;
    for (int k=lg; k>=0; k--)
        if (pos + (1 << k) <= K && aib[pos + (1 << k)] >= max (A[i], B[i]))
            pos += 1 << k, followingSteps += cnt[pos];
    if (pos != K && A[i] < B[i])
        swap (A[i], B[i]);
    int val = (followingSteps % 2 ? B[i] : A[i]);
    sum += val;
}
printf ("%lld\n", sum);
return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d", &N, &K);
 ~~~~~~^~~~~~~~~~~~~~~~~
fortune_telling2.cpp:29:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &A[i], &B[i]), id[i] = i;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
fortune_telling2.cpp:32:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d", &h[i].first), h[i].second = i;
     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 3 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 3 ms 892 KB Output is correct
14 Correct 10 ms 1248 KB Output is correct
15 Correct 33 ms 2204 KB Output is correct
16 Correct 30 ms 3296 KB Output is correct
17 Correct 40 ms 4680 KB Output is correct
18 Correct 46 ms 5868 KB Output is correct
19 Correct 39 ms 6968 KB Output is correct
20 Correct 39 ms 8132 KB Output is correct
21 Correct 38 ms 9296 KB Output is correct
22 Correct 26 ms 9948 KB Output is correct
23 Correct 25 ms 10708 KB Output is correct
24 Correct 28 ms 11268 KB Output is correct
25 Correct 26 ms 12060 KB Output is correct
26 Correct 29 ms 13016 KB Output is correct
27 Correct 35 ms 14172 KB Output is correct
28 Correct 33 ms 15320 KB Output is correct
29 Correct 38 ms 16476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 3 ms 892 KB Output is correct
14 Correct 10 ms 1248 KB Output is correct
15 Correct 33 ms 2204 KB Output is correct
16 Correct 30 ms 3296 KB Output is correct
17 Correct 40 ms 4680 KB Output is correct
18 Correct 46 ms 5868 KB Output is correct
19 Correct 39 ms 6968 KB Output is correct
20 Correct 39 ms 8132 KB Output is correct
21 Correct 38 ms 9296 KB Output is correct
22 Correct 26 ms 9948 KB Output is correct
23 Correct 25 ms 10708 KB Output is correct
24 Correct 28 ms 11268 KB Output is correct
25 Correct 26 ms 12060 KB Output is correct
26 Correct 29 ms 13016 KB Output is correct
27 Correct 35 ms 14172 KB Output is correct
28 Correct 33 ms 15320 KB Output is correct
29 Correct 38 ms 16476 KB Output is correct
30 Correct 76 ms 20852 KB Output is correct
31 Correct 104 ms 24212 KB Output is correct
32 Correct 144 ms 28620 KB Output is correct
33 Correct 207 ms 35680 KB Output is correct
34 Correct 74 ms 35680 KB Output is correct
35 Correct 218 ms 43552 KB Output is correct
36 Correct 222 ms 49428 KB Output is correct
37 Correct 231 ms 55156 KB Output is correct
38 Correct 213 ms 60908 KB Output is correct
39 Correct 217 ms 66704 KB Output is correct
40 Correct 199 ms 72320 KB Output is correct
41 Correct 266 ms 78156 KB Output is correct
42 Correct 223 ms 83956 KB Output is correct
43 Correct 141 ms 89136 KB Output is correct
44 Correct 141 ms 94208 KB Output is correct
45 Correct 161 ms 99288 KB Output is correct
46 Correct 193 ms 103228 KB Output is correct
47 Correct 154 ms 107060 KB Output is correct
48 Correct 194 ms 113000 KB Output is correct
49 Correct 188 ms 118836 KB Output is correct