Submission #91724

#TimeUsernameProblemLanguageResultExecution timeMemory
91724SamAndWeighting stones (IZhO11_stones)C++17
100 / 100
72 ms7672 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...