Submission #91724

# Submission time Handle Problem Language Result Execution time Memory
91724 2018-12-29T15:10:31 Z SamAnd Weighting stones (IZhO11_stones) C++17
100 / 100
72 ms 7672 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct ban
{
    int l, r;
    ban()
    {
        l = r = 0;
    }
    ban(int l, int r)
    {
        this->l = l;
        this->r = r;
    }
};

int n;
ban t[2][N * 4];

ban mer(ban l, ban r)
{
    ban res;
    res.l = l.l;
    res.r = r.r;
    if (l.r + r.l >= 0)
        res.l += (l.r + r.l);
    else
        res.r += (l.r + r.l);
    return res;
}

void ubd(int z, int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        if (y == 1)
            t[z][pos] = ban(1, 0);
        else
            t[z][pos] = ban(0, -1);
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(z, tl, m, x, y, pos * 2);
    else
        ubd(z, m + 1, tr, x, y, pos * 2 + 1);
    t[z][pos] = mer(t[z][pos * 2], t[z][pos * 2 + 1]);
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        if (y == 1)
        {
            ubd(0, 1, n, x, 1, 1);
            ubd(1, 1, n, x, -1, 1);
        }
        else
        {
            ubd(0, 1, n, x, -1, 1);
            ubd(1, 1, n, x, 1, 1);
        }
        if (t[0][1].r == 0)
            printf(">\n");
        else if (t[1][1].r == 0)
            printf("<\n");
        else
            printf("?\n");
    }
    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
stones.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6520 KB Output is correct
2 Correct 7 ms 6520 KB Output is correct
3 Correct 7 ms 6648 KB Output is correct
4 Correct 7 ms 6648 KB Output is correct
5 Correct 7 ms 6648 KB Output is correct
6 Correct 8 ms 6520 KB Output is correct
7 Correct 7 ms 6520 KB Output is correct
8 Correct 7 ms 6520 KB Output is correct
9 Correct 7 ms 6520 KB Output is correct
10 Correct 12 ms 6520 KB Output is correct
11 Correct 44 ms 7160 KB Output is correct
12 Correct 72 ms 7420 KB Output is correct
13 Correct 54 ms 7544 KB Output is correct
14 Correct 54 ms 7636 KB Output is correct
15 Correct 57 ms 7544 KB Output is correct
16 Correct 58 ms 7544 KB Output is correct
17 Correct 53 ms 7544 KB Output is correct
18 Correct 57 ms 7672 KB Output is correct
19 Correct 53 ms 7544 KB Output is correct
20 Correct 52 ms 7524 KB Output is correct
21 Correct 53 ms 7544 KB Output is correct
22 Correct 58 ms 7544 KB Output is correct
23 Correct 54 ms 7544 KB Output is correct
24 Correct 56 ms 7544 KB Output is correct
25 Correct 53 ms 7524 KB Output is correct