Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _____ _ _ _ _
- |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
- | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
- | | | | | | __// ___ \| | | \__ \ | | | |_| | |
- |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
- */
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define pb push_back
- #define ppb pop_back
- #define endl '\n'
- #define mii map<ll,ll>
- #define msi map<string,ll>
- #define mis map<ll, string>
- #define rep(i,a,b) for(ll i=a;i<b;i++)
- #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
- #define trav(a, x) for(auto& a : x)
- #define pii pair<ll,ll>
- #define vi vector<ll>
- #define vii vector<pair<ll, ll>>
- #define vs vector<string>
- #define all(a) (a).begin(),(a).end()
- // #define F first
- #define S second
- #define sz(x) (ll)x.size()
- #define hell 1000000007
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define max(a,b) (a>b?a:b)
- #define min(a,b) (a<b?a:b)
- /* For Debugging */
- #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
- #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
- #define what_is(x) cerr << #x << " is " << x << endl;
- std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
- #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
- #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
- #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
- #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- using namespace __gnu_pbds;
- using namespace std;
- #define PI 3.141592653589793
- #define N 100005
- typedef struct item * pitem;
- struct item {
- int prior, value, cnt, num;
- int F;
- pitem l, r;
- item(int prior,int value,int num) : prior(prior),value(value),num(num),cnt(1),F(num),l(NULL),r(NULL) {};
- };
- void display1(pitem it) {
- cout<<"prior: "<<it->prior<<" value: "<<it->value<<" cnt: "<<it->cnt<<" F: "<<it->F<<endl;
- }
- int cnt (pitem it) {
- return it ? it->cnt : 0;
- }
- void upd_cnt (pitem it) {
- if (it)
- it->cnt = cnt(it->l) + cnt(it->r) + 1;
- }
- int find_F (pitem it) {
- return it ? it->F : 0;
- }
- void update_F (pitem it) {
- if (it) {
- it->F = find_F(it->l) + find_F(it->r) + it->num;
- }
- }
- void merge (pitem & t, pitem l, pitem r) {
- if (!l || !r)
- t = l ? l : r;
- else if (l->prior > r->prior)
- merge (l->r, l->r, r), t = l;
- else
- merge (r->l, l, r->l), t = r;
- upd_cnt (t);
- update_F(t);
- // display1(t);
- }
- void split (pitem t, pitem & l, pitem & r, int key) {
- if (!t)
- return void( l = r = 0 );
- // int cur_key = add + cnt(t->l);
- if (key < t->value)
- split (t->l, l, t->l, key), r = t;
- else
- split (t->r, t->r, r, key), l = t;
- upd_cnt (t);
- update_F(t);
- }
- void output (pitem t) {
- if (!t) return;
- output (t->l);
- cout<<t->value<<" ";
- output (t->r);
- }
- void solve()
- {
- ll q,sum=0;
- cin>>q;
- ll a,b;
- pitem t=NULL,t1,t2,t3,t4,t5;
- rep(i,0,q) {
- cin>>a>>b;
- // what_is(sum);
- // cout<<(a^sum)<<" "<<(b^sum)<<endl;
- t1=NULL,t2=NULL,t3=NULL,t4=NULL,t5=NULL;
- split(t,t1,t2,(a^sum));
- t3 = new item(rand(),(a^sum),(b^sum));
- // what_is(t3->F);
- // output(t1);
- // cout<<endl;
- merge(t4,t1,t3);
- cout<<(a^sum)<<" "<<t4->F<<endl;
- sum=t4->F;
- merge(t5,t4,t2);
- t = t5;
- // output(t);
- // cout<<endl;
- }
- return;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- // freopen ("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- #endif
- FAST
- int TESTS=1;
- // cin>>TESTS;
- while(TESTS--)
- {
- solve();
- }
- TIME
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment