Submission #43185

# Submission time Handle Problem Language Result Execution time Memory
43185 2018-03-10T13:05:55 Z jwvg0425 즐거운 사진 수집 (JOI13_collecting) C++14
0 / 100
5000 ms 25200 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <sstream>
#include <iterator>
#include <regex>
#define MOD 1000000007

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

class FenwickTree
{
public:
    FenwickTree(int k)
    {
        data.resize(k);
    }

    i64 sum(int n)
    {
        i64 ans = 0;

        while (n > 0)
        {
            ans += data[n];
            n -= (n & -n);
        }

        return ans;
    }

    void add(int n, i64 num)
    {
        while (n < data.size())
        {
            data[n] += num;
            n += (n & -n);
        }
    }

private:
    vector<i64> data;
};

int total = 1;

void update(int x, int y, int n, FenwickTree& lr, FenwickTree& ud, int change)
{
    if (n == 1)
        return;

    int lrt = lr.sum(x + n - 1) - lr.sum(x - 1);
    int udt = ud.sum(y + n - 1) - ud.sum(y - 1);

    //다 같은 색
    if ((udt==0 || udt == n))
    {
        if ((lrt == 0 || lrt == n))
            total -= 4;
        else if ((lrt == 1 || lrt == n - 1)) // 원래 통째로 였다가 나뉜거
            total += 4;
    }

    int hn = n / 2;

    if (change < x + hn)
    {
        update(x, y, hn, lr, ud, change);
        update(x, y + hn, hn, lr, ud, change);
    }
    else
    {
        update(x + hn, y, hn, lr, ud, change);
        update(x + hn, y + hn, hn, lr, ud, change);
    }
}

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    vector<int> lr((1 << n) + 1);
    vector<int> ud((1 << n) + 1);
    FenwickTree lrtree((1 << n) + 1);
    FenwickTree udtree((1 << n) + 1);

    for (int i = 0; i < q; i++)
    {
        int t, x;
        scanf("%d %d", &t, &x);

        vector<int>& v = t == 0 ? lr : ud;
        FenwickTree& tree = t == 0 ? lrtree : udtree;
        FenwickTree& other = t == 0 ? udtree : lrtree;

        int prev = v[x];

        if (v[x] == 0)
            v[x] = 1;
        else
            v[x] = 0;

        tree.add(x, v[x] - prev); 
        update(1, 1, (1 << n), tree, other, x);
        printf("%d\n", total);
    }

    return 0;
}

Compilation message

collecting.cpp: In member function 'void FenwickTree::add(int, i64)':
collecting.cpp:51:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (n < data.size())
                  ^
collecting.cpp: In function 'int main()':
collecting.cpp:98:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
                           ^
collecting.cpp:108:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &t, &x);
                               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5076 ms 25200 KB Time limit exceeded
2 Halted 0 ms 0 KB -