Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef tree<int,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define MOD 1000000007
- #define PI 3.14159265
- //#define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
- #define imin INT_MIN
- #define imax INT_MAX
- #define nl '\n'
- #define modulo(a, b, m) ((a % m) * (b % m)) % m
- void Start_Crushing() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- //vector<int> dx = {0, 0, 1, -1, 1, 1, -1, -1}, dy = {1, -1, 0, 0, 1, -1, 1, -1};
- //int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
- void solve(){
- ll n, q, type; cin >> n >> q;
- while(q-- and cin >> type){
- if(type == 1){
- for(int bit = 0; bit < 32; bit++){
- if(!(n & (1 << bit))){
- n |= (1 << bit);
- break;
- }
- }
- cout << n;
- }else if(type == 2){
- for(int bit = 0; bit < 32; bit++){
- if(n & (1 << bit)){
- n = n & ~(1 << bit);
- break;
- }
- }
- cout << n;
- }else if(type == 3){
- for (int bit = 0; bit < 32; bit++) {
- if (n & (1 << bit)) break;
- n |= (1 << bit);
- }
- cout << n;
- }else if(type == 4){
- for(int bit = 0; bit < 32; bit++){
- if(!(n & (1 << bit))) break;
- n = n & ~(1 << bit);
- }
- cout << n;
- }else{
- cout << (__builtin_popcount(n) == 1 ? "is power of two" : "not power of two");
- }
- cout << nl;
- }
- }
- int main(){
- // freopen("equal.in", "r", stdin);
- Start_Crushing();
- int t = 1;
- // /*is Single Test case?*/ cin >> t;
- while (t--) {
- solve();
- if(!t) break;
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement