https://www.acmicpc.net/problem/11723

11723번: 집합

첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.

www.acmicpc.net

정말 뭐랄까 입출력때문에 에러나는거 좀 화가 나네요 
차라리 비트마스킹을 안해서 틀렷다고 하면 이해라도 가는데 .. ㅋㅋ 
반드시 아래 이것을 선언해주세요 

ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

iostream의 동기화를 비활성화하고, cin/cout을 묶음(buffer)으로 처리하여 입/출력을 더 빠르게 처리된다고 합니다.

#include <iostream>
#include <vector>
#include <queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<stack>
using namespace std;

struct Point {
	int i, j, t, cnt, power;
	char c;
};

void Prints(vector<vector<int>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<bool>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<char>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<vector<char>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<vector<bool>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<int>line, int n) {
	for (int i = 0; i < n; i++) {
		cout << line[i] << ",";
	}
	cout << endl;
}
void Prints(string str, int n) {
	for (int i = 0; i < n; i++) {
		cout << str[i] << ",";
	}
	cout << endl;
}

struct Data {
	int index;
	int value;
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;

	vector<bool>answer;
	vector<long long> S(1, 0);
	string anwstr = "";
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		int x;

		if (str == "all" || str == "empty") {
			if (str == "all") {

				S[0] = 2 * (pow(2, 20) - 1);
				continue;
			}
			else if (str == "empty") {
				S[0] = 0;
				continue;
			}
		}

		cin >> x;

		if (str == "add") {
			S[0] |= (1 << x);
			continue;
		}
		else if (str == "remove") {
			S[0] &= ~(1 << x);
			continue;
		}
		else if (str == "check") {
			answer.push_back(S[0] & (1 << x));
			continue;
		}
		else if (str == "toggle") {
			if ((S[0] & (1 << x)) != 0) {
				S[0] &= ~(1 << x);//0
			}
			else {
				S[0] |= (1 << x);//1
			}
			continue;
		}
	}

	for (auto ans : answer) {
		cout << ans << '\n';
	}

	return 0;
}

'알고리즘 공부' 카테고리의 다른 글

백준 덩치  (1) 2023.07.31
백준 올림픽  (0) 2023.07.31
백준 줄세우기  (0) 2023.07.30
백준 현수막  (0) 2023.07.30
백준 알고리즘 수업 -깊이 우선 탐색4  (0) 2023.07.30

+ Recent posts