結果

問題 No.1641 Tree Xor Query
ユーザー noya2noya2
提出日時 2021-08-06 22:30:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 5,000 ms
コード長 4,293 bytes
コンパイル時間 4,331 ms
コンパイル使用メモリ 281,900 KB
実行使用メモリ 24,024 KB
最終ジャッジ日時 2024-09-17 02:33:38
合計ジャッジ時間 5,788 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 176 ms
23,896 KB
testcase_14 AC 193 ms
24,024 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 14 ms
6,948 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 9 ms
6,944 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 151 ms
15,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using bint = mp::cpp_int;
*/
#include <atcoder/all>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define repb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define fi first
#define se second
#define endl "\n"
using namespace std;
using namespace atcoder;
//using namespace internal;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
const int INF = 1001001007;
const long long mod1 = 1000000007LL;
const long long mod2 = 998244353LL;
const ll inf = 2e18;
const ld pi = 3.14159265358979323;
template<typename T>void priv(vector<T> &v){if(v.size()==0){cout<<endl;}else{rep(i,v.size()-1)cout<<v[i]<<" ";cout<<v[v.size()-1]<<endl;}}
template<typename T>void privv(vector<vector<T>> &v){rep(i,v.size()){rep(j,v[i].size()-1)cout<<v[i][j]<<" ";cout<<v[i][v[i].size()-1]<<endl;}}
template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);}
template<typename T>bool rrange(pair<T,T> a,pair<T,T> b,pair<T,T> x){return (range(a.fi,b.fi,x.fi)&&range(a.se,b.se,x.se));}
template<typename T>void rev(vector<T> &v){reverse(v.begin(),v.end());}
template<typename T>void sor(vector<T> &v, int f=0){sort(v.begin(),v.end());if(f!=0) rev(v);}
template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<typename T>void eru(vector<T> &v){sor(v);v.erase(unique(v.begin(),v.end()),v.end());}
template<typename T>T cel(T a,T b){if (a%b==0)return a/b;return a/b +1;}
template<typename T,typename U> void pout(pair<T,U> p){cout<<p.fi<<" "<<p.se<<endl;}
template<typename T>void myswap(T &a,T &b){if(a>b)swap(a,b);}
void yes(){cout << "Yes" << endl;}
void no (){cout << "No" << endl;}
void yn (bool t){if(t)yes();else no();}
void Yes(){cout << "YES" << endl;}
void No (){cout << "NO" << endl;}
void YN (bool t){if(t)Yes();else No();}
void dout() {cout << setprecision(20);}
void deb(ll h = INF-1) {cout << (h == INF-1 ? "!?" : to_string(h)) << endl;}
void revs(string &s) {reverse(s.begin(),s.end());}
vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string num = "0123456789";

ll gcds(ll a, ll b){
    a = abs(a); b = abs(b);
    if (b == 0) return a;
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll tentou(vector<ll> ar){
    int n = ar.size();
    set<ll> st;
    rep(i,n) st.insert(ar[i]);
    map<ll,int> mp;
    int ind = 0;
    for (ll x : st){
        mp[x] = ind;
        ind++;
    }
    fenwick_tree<ll> fw(ind);
    ll ans = 0;
    rep(i,n){
        int a = mp[ar[i]];
        ans += i - fw.sum(0,a+1);
        fw.add(a,1);
    }
    return ans;
}

/*
alias g++='g++ -I/mnt/c/Users/Owner/Desktop/ac-library'
*/

ll op(ll a, ll b){
    return a ^ b;
}

ll e(){
    return 0LL;
}

struct vs{
    vector<int> to;
};

int t = 0;

void eul(vector<int> &in, vector<int> &out, vector<vs> &ar, int x){
    in[x] = t;
    t++;
    for (int y : ar[x].to){
        if (in[y] == -1) eul(in,out,ar,y);
    }
    out[x] = t;
    t++;
}

int main(){
    int n, q; cin >> n >> q;
    vector<ll> c(n);
    rep(i,n) cin >> c[i];
    segtree<ll,op,e> seg(2*n+10);
    vector<int> in(n,-1);
    vector<int> out(n,-1);
    vector<vs> ar(n);
    rep(i,n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        ar[a].to.emplace_back(b);
        ar[b].to.emplace_back(a);
    }
    eul(in,out,ar,0);
    rep(i,n) seg.set(in[i],c[i]);
    vector<ll> ans;
    rep(i,q){
        int g; cin >> g;
        ll x, y; cin >> x >> y;
        if (g == 1){
            seg.set(in[x-1],seg.get(in[x-1])^y);
        }
        if (g == 2){
            ans.emplace_back(seg.prod(in[x-1],out[x-1]));
        }
    }
    for (ll x : ans) cout << x << endl;
}
0