Submission #43162433


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define vvi vector<vector<ll>>
#define vi vector<ll>
#define umap unordered_map
#define pi pair<ll,ll>
#define vpi vector<pi>
#define ff first
#define ss second
#define yeah cout <<"Yes"<<'\n';
#define nope cout <<"No"<< '\n';
#define _print(a)  for(auto &x : a ) cout << x << " "; cout<<'\n';
#define inp(a)  for(auto &x : a) cin>>x;
#define nl cout<<'\n';
#define pb push_back
#define forn(i,n)  for(ll i=0;i < ll(n);i++)
#define all(x) (x).begin(), (x).end()
#define pq priority_queue

const int MOD = 1e9+7;
ll inf = 11e17;

ll bpm(ll  a, ll  b, ll  m) { a %= m; a+= (a<0)*m;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = (res * a)% m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

ll inv(ll n) {return bpm(n, MOD-2, MOD);}

// ll phi(ll n){
//     ll result = n;
//     for(ll p = 2; p * p <= n; ++p){
//         if (n % p == 0){
//             while (n % p == 0)
//                 n /= p;
//                 result -= result / p;
//         }
//     }
//     if(n > 1) result -= result / n;   
//     return result;
// }

//vector<pi> dr ={{1,0},{0,1},{-1,0},{0,-1}};

template<class a, class b>
istream& operator>>(istream& is, pair<a, b> & v){
    is>>v.first>>v.second;
    return is;
}
template<class a, class b>
ostream& operator<<(ostream& os, pair<a, b> & v){
    os<<(v.first)<< ' ' <<(v.second)<<'\n';
    return os;
}

template<class T>
istream& operator>>(istream& is, vector<T> & v){
    for(auto &x: v) is>>x;
    return is;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> & v)
{
    for(auto x: v) os<<x<<' '; cout<<'\n';
    return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T> & v)
{
    for(auto x: v) os<<x<<' '; cout<<'\n';
    return os;
}
template<class T>
ostream& operator<<(ostream& os, const multiset<T> & v)
{
    for(auto x: v) os<<x<<' '; cout<<'\n';
    return os;
}


const int nax = 3e5+100;
// vi adj[nax];

// int inf = (1<<31);
const int SZ = 1<<30;
template<class T> struct node {
	T val = inf; node<T>* c[2];
    ll num = -1;
    int sz = 0;
	node() { c[0] = c[1] = NULL; }


    void recalc(int ind){
        if(sz>1){
            val = 0;
            num = -1;
        } 
        else {
            val = inf;
            if(sz) num = ind;
            else num = -1;
        }
        return;
    }
    void combine(){
        val = inf;
        if(sz==0){
            num = -1;
        }else if(sz == 1){
            for(int i=0; i<2; i++){
                if(c[i] && c[i]->num != -1){
                    num = c[i] -> num;
                }
            }
        }else{
            for(int i=0; i<2; i++)
                if(c[i]) val = min(val, c[i]->val);
            if(val==inf){
                val = c[0]->num ^ c[1]->num;
            }
        }
    }


	void add(int ind, int L = 0, int R = SZ-1) { // add v
        sz++;
		if (L == ind && R == ind){
            recalc(ind);
            return;
        } 
		int M = (L+R)/2;
		if (ind <= M) {
			if (!c[0]) c[0] = new node();
			c[0]->add(ind,L,M);
		} else {
			if (!c[1]) c[1] = new node();
			c[1]->add(ind,M+1,R);
		}
        combine();

	}
    void rem(int ind, int L = 0, int R = SZ-1) { 
        sz--;
		if (L == ind && R == ind){
            recalc(ind);
            return;
        }
		int M = (L+R)/2;
		if (ind <= M) {
			if (!c[0]) c[0] = new node();
			c[0]->rem(ind,L,M);
		} else {
			if (!c[1]) c[1] = new node();
			c[1]->rem(ind,M+1,R);
		}

        combine();
    }

};


ll n,m,k;


ll i, j;

void solve(int tc = 0){
    //cout<<'#'<<tc<<'\n';
    int q;
    cin>>q;
    node<ll> n;
    while(q--){
        int t; cin>>t;
        if(t==1){
            int x; cin>>x;
            n.add(x);
        }else if(t==2){
            int x; cin>>x;
            n.rem(x);
        }else{
            cout<<n.val<<'\n';
        }
    }
}


int main()
{
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    cout<<setprecision(15)<<fixed;

    // ncr();

    srand(chrono::steady_clock::now().time_since_epoch().count());

    ll tt=1;
    // cin>>tt;
    for(ll t =1 ; t <= tt ; t++) {
        solve(t);
    }
    cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;

}

Submission Info

Submission Time
Task G - Minimum Xor Pair Query
User Sanat_
Language C++ (GCC 9.2.1)
Score 600
Code Size 4491 Byte
Status AC
Exec Time 434 ms
Memory 185404 KiB

Compile Error

./Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)’:
./Main.cpp:72:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   72 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |     ^~~
./Main.cpp:72:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   72 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |                                ^~~~
./Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const std::set<T>&)’:
./Main.cpp:78:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   78 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |     ^~~
./Main.cpp:78:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   78 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |                                ^~~~
./Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const std::multiset<T>&)’:
./Main.cpp:84:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   84 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |     ^~~
./Main.cpp:84:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   84 |     for(auto x: v) os<<x<<' '; cout<<'\n';
      |                                ^~~~
./Main.cpp: In function ‘void solve(int)’:
./Main.cpp:176:16: warning: unused parameter ‘tc’ [-Wunused-parameter]
  176 | void solve(int tc = 0){
      |            ~~~~^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 25
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 7 ms 3640 KiB
01_test_01.txt AC 316 ms 130216 KiB
01_test_02.txt AC 315 ms 130312 KiB
01_test_03.txt AC 316 ms 130268 KiB
01_test_04.txt AC 316 ms 130216 KiB
01_test_05.txt AC 314 ms 130356 KiB
01_test_06.txt AC 318 ms 130352 KiB
01_test_07.txt AC 308 ms 130320 KiB
01_test_08.txt AC 297 ms 130300 KiB
01_test_09.txt AC 164 ms 56088 KiB
01_test_10.txt AC 170 ms 56184 KiB
01_test_11.txt AC 163 ms 56148 KiB
01_test_12.txt AC 165 ms 56204 KiB
01_test_13.txt AC 168 ms 56432 KiB
01_test_14.txt AC 170 ms 56484 KiB
01_test_15.txt AC 184 ms 59360 KiB
01_test_16.txt AC 184 ms 59360 KiB
01_test_17.txt AC 75 ms 3696 KiB
01_test_18.txt AC 434 ms 185272 KiB
01_test_19.txt AC 424 ms 185404 KiB
01_test_20.txt AC 231 ms 101520 KiB
01_test_21.txt AC 229 ms 101432 KiB
01_test_22.txt AC 298 ms 101548 KiB
01_test_23.txt AC 299 ms 101668 KiB
01_test_24.txt AC 86 ms 3636 KiB