Submission #844892

# Submission time Handle Problem Language Result Execution time Memory
844892 2023-09-06T07:14:45 Z vjudge1 Klasika (COCI20_klasika) C++17
0 / 110
715 ms 87384 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define tol(bi) (1LL<<((int)(bi)))
int LOG = 23;
struct Trie{
	struct Node{
		set<int> st;
		Node *lnode, *rnode;
		inline bool check(int l, int r){
			return (st.lower_bound(l)!=st.end() && *st.lower_bound(l)<=r);
		}
		inline void crl(){
			if (lnode==nullptr) lnode=new Node;
		}
		inline void crr(){
			if (rnode==nullptr) rnode=new Node;
		}
		inline void insert(int x){
			st.insert(x);
		}
		Node():lnode(nullptr), rnode(nullptr){}
	};
	Node* root;
	Trie():root(new Node){}
	void insert(int x, int t){
		//cout<<"Inserted: "<<x<<", "<<t<<endl;
		Node* node=root;
		for (int i = LOG; i >= 0; i--){
			if (x&tol(i)){
				node->crr();
				node=node->rnode;
			}
			else {
				node->crl();
				node=node->lnode;
			}
			node->insert(t);
		}
	}
	int query(int x, int l, int r){
		//cout<<"Queried: "<<x<<", "<<l<<", "<<r<<endl; 
		Node* node = root;
		int ans = 0;
		for (int i = LOG; i >= 0; i--){
			bool bb;
			if (x&tol(i)){
				bb=true;
				if (node->lnode==nullptr || !node->lnode->check(l,r)){
					bb = false;
				}
				else ans+=tol(i);
			}
			else {
				bb=false;
				if (node->rnode==nullptr || !node->rnode->check(l,r)){
					bb=true;
				}
				else ans+=tol(i);
			}
			if (bb){
				node=node->lnode;
			}
			else {
				node=node->rnode;
			}
		}
		return ans;
	}
};
int32_t main(){
	int q;cin>>q;
	vector<array<int,3>> qu;
	vector<vector<int>> arr;
	arr.push_back(vector<int>());
	vector<int> vals(1,0);
	for (int i = 0; i < q; ++i)
	{
		string str;cin>>str;
		int x, y;cin>>x>>y;x--,y--;
		qu.push_back({str=="Add", x, y});
		if (str=="Add") {
			vals.push_back(vals[x]^(y+1));
			arr[x].push_back(arr.size());
			arr.push_back(vector<int>());
		}
	}
	int n = arr.size();
	vector<int> l(n), r(n);
	int time=0;
	auto dfs = [&](int node, auto dfs)->void{
		time++;
		l[node]=time;
		time++;
		for (int i = 0; i < arr[node].size(); i++){
			time++;
			dfs(arr[node][i], dfs);
			time++;
		}
		time++;
		r[node]=time;
		time++;
	};
	dfs(0,dfs);
	for (auto &it : l) cout<<it<<" ";cout<<endl;
	for (auto &it : r) cout<<it<<" ";cout<<endl;
	Trie trie;
	trie.insert(vals[0],l[0]);
	int hehe = 1;
	for (int i = 0; i < q; i++){
		if (qu[i][0]){
			trie.insert(vals[hehe], l[hehe]);
			hehe++;
		}
		else {
			cout<<trie.query(vals[qu[i][1]], l[qu[i][2]], r[qu[i][2]])<<endl;
		}
	}
}

Compilation message

klasika.cpp: In function 'int32_t main()':
klasika.cpp:105:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  105 |  for (auto &it : l) cout<<it<<" ";cout<<endl;
      |  ^~~
klasika.cpp:105:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  105 |  for (auto &it : l) cout<<it<<" ";cout<<endl;
      |                                   ^~~~
klasika.cpp:106:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  106 |  for (auto &it : r) cout<<it<<" ";cout<<endl;
      |  ^~~
klasika.cpp:106:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  106 |  for (auto &it : r) cout<<it<<" ";cout<<endl;
      |                                   ^~~~
klasika.cpp: In instantiation of 'main()::<lambda(long long int, auto:23)> [with auto:23 = main()::<lambda(long long int, auto:23)>]':
klasika.cpp:104:11:   required from here
klasika.cpp:95:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |   for (int i = 0; i < arr[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 715 ms 87384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -