-
Notifications
You must be signed in to change notification settings - Fork 67
/
ADAFUROW.cpp
59 lines (51 loc) · 1.47 KB
/
ADAFUROW.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// main.cpp
// practice
//
// Created by Mahmud on 11/02/17.
// Copyright © 2017 Mahmud. All rights reserved.
//
/*
O(Q * MAX(N) / 32) solution using bitsets
MAX(N) defines maximum of input numbers which can be up to 20000.
32 factor comes from bitsets (basically, it is 32 times faster than normal boolean array).
For more precise definition of bitsets, please google it.
Every query is just playing with bitsets :).
Note: The solution can be boosted at least 2 times with implementing your 64-bit bitset technique.
And if you need more interesting problem related to bitsets, you can try the following one:
http://www.spoj.com/problems/ADATOMEL/
*/
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
const int MAX = 20005;
int N, Q;
bitset<MAX> bs[MAX];
int main() {
scanf("%d", &Q);
while (Q --) {
char ch;
int x, y;
scanf(" %c%d%d", &ch, &x, &y);
if (ch == '+') {
bs[x][y] = 1;
}
else if(ch == '-') {
bs[x][y] = 0;
}
else if (ch == 'v') {
printf("%d\n", int((bs[x] | bs[y]).count()));
}
else if(ch == '^') {
printf("%d\n", int((bs[x] & bs[y]).count()));
}
else if(ch == '!') {
printf("%d\n", int((bs[x] | bs[y]).count()) - int((bs[x] & bs[y]).count()));
}
else {
printf("%d\n", int((bs[x] ^ (bs[x] & bs[y])).count()));
}
}
return 0;
}