Submission #51748

# Submission time Handle Problem Language Result Execution time Memory
51748 2018-06-21T00:36:20 Z gs13105 None (JOI16_ho_t5) C++17
100 / 100
303 ms 10948 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct que
{
    int x, d, l;
};

que inp[200010];

long long idx1[525000]; // y + x
long long idx2[525000]; // y - x
int bp;

void add(long long idx[], int x, int y, int v)
{
    if(y < x)
        return;
    x += bp;
    y += bp;
    while(x < y)
    {
        if(x % 2 == 1)
            idx[x++] += v;
        if(y % 2 == 0)
            idx[y--] += v;
        x /= 2;
        y /= 2;
    }
    if(x == y)
        idx[x] += v;
}

long long sum(long long idx[], int x)
{
    long long r = 0;
    x += bp;
    while(x)
    {
        r += idx[x];
        x /= 2;
    }
    return r;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, q, i;
    scanf("%d%d", &n, &q);
    for(i = 1; i <= q; i++)
        scanf("%d%d%d", &inp[i].x, &inp[i].d, &inp[i].l);

    for(bp = 1; bp <= n; bp *= 2);

    for(i = 1; i <= n; i++)
    {
        add(idx1, i, i, i);
        add(idx2, i, i, -i);
    }

    for(i = q; i >= 1; i--)
    {
        if(inp[i].d == 1)
        {
            int s = 0;
            int g = n;
            while(s < g)
            {
                int x = (s + g + 1) / 2;
                if(sum(idx2, x) + inp[i].x >= 0)
                    s = x;
                else
                    g = x - 1;
            }
            add(idx1, 1, s, -2 * inp[i].l);
        }
        else
        {
            int s = 1;
            int g = n + 1;
            while(s < g)
            {
                int x = (s + g) / 2;
                if(sum(idx1, x) - inp[i].x - 1 >= 0)
                    g = x;
                else
                    s = x + 1;
            }
            add(idx2, s, n, -2 * inp[i].l);
        }
    }

    for(i = 1; i <= n; i++)
    {
        long long r = -(sum(idx1, i) + sum(idx2, i)) / 2;
        printf("%lld\n", r);
    }
    return 0;
}

Compilation message

2016_ho_t5.cpp: In function 'int main()':
2016_ho_t5.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
2016_ho_t5.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &inp[i].x, &inp[i].d, &inp[i].l);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 2 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 3 ms 624 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 2 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 3 ms 624 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 4 ms 764 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 4 ms 780 KB Output is correct
31 Correct 4 ms 916 KB Output is correct
32 Correct 4 ms 916 KB Output is correct
33 Correct 5 ms 916 KB Output is correct
34 Correct 4 ms 916 KB Output is correct
35 Correct 5 ms 916 KB Output is correct
36 Correct 5 ms 916 KB Output is correct
37 Correct 5 ms 916 KB Output is correct
38 Correct 6 ms 916 KB Output is correct
39 Correct 4 ms 924 KB Output is correct
40 Correct 5 ms 924 KB Output is correct
41 Correct 5 ms 924 KB Output is correct
42 Correct 5 ms 924 KB Output is correct
43 Correct 4 ms 924 KB Output is correct
44 Correct 5 ms 924 KB Output is correct
45 Correct 4 ms 924 KB Output is correct
46 Correct 4 ms 924 KB Output is correct
47 Correct 6 ms 944 KB Output is correct
48 Correct 5 ms 944 KB Output is correct
49 Correct 5 ms 944 KB Output is correct
50 Correct 5 ms 960 KB Output is correct
51 Correct 4 ms 960 KB Output is correct
52 Correct 6 ms 960 KB Output is correct
53 Correct 5 ms 960 KB Output is correct
54 Correct 5 ms 960 KB Output is correct
55 Correct 4 ms 960 KB Output is correct
56 Correct 4 ms 960 KB Output is correct
57 Correct 5 ms 960 KB Output is correct
58 Correct 5 ms 960 KB Output is correct
59 Correct 5 ms 960 KB Output is correct
60 Correct 4 ms 960 KB Output is correct
61 Correct 4 ms 960 KB Output is correct
62 Correct 4 ms 960 KB Output is correct
63 Correct 5 ms 960 KB Output is correct
64 Correct 4 ms 960 KB Output is correct
65 Correct 4 ms 960 KB Output is correct
66 Correct 5 ms 960 KB Output is correct
67 Correct 4 ms 960 KB Output is correct
68 Correct 4 ms 960 KB Output is correct
69 Correct 4 ms 960 KB Output is correct
70 Correct 3 ms 960 KB Output is correct
71 Correct 3 ms 960 KB Output is correct
72 Correct 3 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 2 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 3 ms 624 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 4 ms 764 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 4 ms 780 KB Output is correct
31 Correct 4 ms 916 KB Output is correct
32 Correct 4 ms 916 KB Output is correct
33 Correct 5 ms 916 KB Output is correct
34 Correct 4 ms 916 KB Output is correct
35 Correct 5 ms 916 KB Output is correct
36 Correct 5 ms 916 KB Output is correct
37 Correct 5 ms 916 KB Output is correct
38 Correct 6 ms 916 KB Output is correct
39 Correct 4 ms 924 KB Output is correct
40 Correct 5 ms 924 KB Output is correct
41 Correct 5 ms 924 KB Output is correct
42 Correct 5 ms 924 KB Output is correct
43 Correct 4 ms 924 KB Output is correct
44 Correct 5 ms 924 KB Output is correct
45 Correct 4 ms 924 KB Output is correct
46 Correct 4 ms 924 KB Output is correct
47 Correct 6 ms 944 KB Output is correct
48 Correct 5 ms 944 KB Output is correct
49 Correct 5 ms 944 KB Output is correct
50 Correct 5 ms 960 KB Output is correct
51 Correct 4 ms 960 KB Output is correct
52 Correct 6 ms 960 KB Output is correct
53 Correct 5 ms 960 KB Output is correct
54 Correct 5 ms 960 KB Output is correct
55 Correct 4 ms 960 KB Output is correct
56 Correct 4 ms 960 KB Output is correct
57 Correct 5 ms 960 KB Output is correct
58 Correct 5 ms 960 KB Output is correct
59 Correct 5 ms 960 KB Output is correct
60 Correct 4 ms 960 KB Output is correct
61 Correct 4 ms 960 KB Output is correct
62 Correct 4 ms 960 KB Output is correct
63 Correct 5 ms 960 KB Output is correct
64 Correct 4 ms 960 KB Output is correct
65 Correct 4 ms 960 KB Output is correct
66 Correct 5 ms 960 KB Output is correct
67 Correct 4 ms 960 KB Output is correct
68 Correct 4 ms 960 KB Output is correct
69 Correct 4 ms 960 KB Output is correct
70 Correct 3 ms 960 KB Output is correct
71 Correct 3 ms 960 KB Output is correct
72 Correct 3 ms 960 KB Output is correct
73 Correct 274 ms 10552 KB Output is correct
74 Correct 287 ms 10644 KB Output is correct
75 Correct 286 ms 10696 KB Output is correct
76 Correct 279 ms 10696 KB Output is correct
77 Correct 303 ms 10696 KB Output is correct
78 Correct 267 ms 10696 KB Output is correct
79 Correct 266 ms 10696 KB Output is correct
80 Correct 233 ms 10820 KB Output is correct
81 Correct 218 ms 10948 KB Output is correct
82 Correct 236 ms 10948 KB Output is correct
83 Correct 257 ms 10948 KB Output is correct
84 Correct 236 ms 10948 KB Output is correct
85 Correct 281 ms 10948 KB Output is correct
86 Correct 231 ms 10948 KB Output is correct
87 Correct 226 ms 10948 KB Output is correct
88 Correct 246 ms 10948 KB Output is correct
89 Correct 297 ms 10948 KB Output is correct
90 Correct 252 ms 10948 KB Output is correct
91 Correct 234 ms 10948 KB Output is correct
92 Correct 210 ms 10948 KB Output is correct
93 Correct 242 ms 10948 KB Output is correct
94 Correct 228 ms 10948 KB Output is correct
95 Correct 242 ms 10948 KB Output is correct
96 Correct 221 ms 10948 KB Output is correct
97 Correct 244 ms 10948 KB Output is correct
98 Correct 256 ms 10948 KB Output is correct
99 Correct 251 ms 10948 KB Output is correct
100 Correct 234 ms 10948 KB Output is correct
101 Correct 254 ms 10948 KB Output is correct
102 Correct 228 ms 10948 KB Output is correct
103 Correct 258 ms 10948 KB Output is correct
104 Correct 227 ms 10948 KB Output is correct
105 Correct 235 ms 10948 KB Output is correct
106 Correct 221 ms 10948 KB Output is correct
107 Correct 221 ms 10948 KB Output is correct
108 Correct 234 ms 10948 KB Output is correct
109 Correct 214 ms 10948 KB Output is correct
110 Correct 204 ms 10948 KB Output is correct
111 Correct 270 ms 10948 KB Output is correct
112 Correct 258 ms 10948 KB Output is correct
113 Correct 260 ms 10948 KB Output is correct
114 Correct 213 ms 10948 KB Output is correct
115 Correct 226 ms 10948 KB Output is correct
116 Correct 229 ms 10948 KB Output is correct
117 Correct 237 ms 10948 KB Output is correct
118 Correct 216 ms 10948 KB Output is correct
119 Correct 41 ms 10948 KB Output is correct
120 Correct 36 ms 10948 KB Output is correct