#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 calcSize(int x, int y, int n, FenwickTree& lr, FenwickTree& ud)
{
int lrt = lr.sum(y + n - 1) - lr.sum(y - 1);
int udt = ud.sum(x + n - 1) - ud.sum(x - 1);
//다 같은 색
if ((lrt == 0 && udt == 0) || (lrt == n && udt == 0) ||
(lrt == 0 && udt == n) || (lrt == n && udt == n))
{
return 1;
}
int hn = n / 2;
return calcSize(x, y, hn, lr, ud) +
calcSize(x + hn, y, hn, lr, ud) +
calcSize(x, y + hn, hn, lr, ud) +
calcSize(x + hn, y + hn, hn, lr, ud) + 1;
}
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;
int prev = v[x];
if (v[x] == 0)
v[x] = 1;
else
v[x] = 0;
tree.add(x, v[x] - prev);
printf("%d\n", calcSize(1, 1, (1 << n), lrtree, udtree));
}
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:85: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:95:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &t, &x);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
17 ms |
412 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
14 ms |
528 KB |
Output is correct |
7 |
Correct |
8 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5022 ms |
624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5021 ms |
25404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |