답안 #933874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933874 2024-02-26T12:49:54 Z pan Klasika (COCI20_klasika) C++17
110 / 110
2090 ms 436784 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
struct query
{
	ll a, b, c;
};
struct node
{
	ll layer;
	set<ll> s;
	node *zero, *one;
	node(ll i)
	{
		layer = i;
		zero = one = nullptr;
	}
	void createl()
	{
		if (layer>=30 || zero!=nullptr)  return;
		zero = new node(layer +1);
	}
	void creater()
	{
		if (layer>=30 || one!=nullptr)  return;
		one = new node(layer +1);
	}
	void insert(ll val, ll time)
	{
		s.insert(time);
		if (layer==30) return; // finish
		bool bit= val&(1<<(30-layer-1));
		if (bit) {creater(); one->insert(val, time);}
		else {createl(); zero->insert(val, time);}

	}
	ll xorquery(ll val, ll l, ll r)
	{
		if (layer==30) return 0;
		bool wanted = !(val&((1<<(30-layer-1))));
		if (wanted)
		{
			if (one!=nullptr)
			{
				auto it = one->s.lb(l);
				if (it!=one->s.end() && *it<=r) return one->xorquery(val, l, r)^(1<<(30-layer-1));
			}
			createl();
			return zero->xorquery(val, l, r);
		}
		else
		{
			if (zero!=nullptr)
			{
				auto it = zero->s.lb(l);
				if (it!=zero->s.end() && *it<=r) return zero->xorquery(val, l, r)^(1<<(30-layer-1));
			}
			creater();
			return one->xorquery(val, l, r);
		}
	}
	
}*root;
ll label = -1;
ll in[200005], out[200005], root_xor[200005];
vector<pi> add[200005];
vector<query> queries;
void dfs(ll x)
{
	in[x] = ++label;
	for (pi u: add[x])
	{
		root_xor[u.f] = root_xor[x]^u.s;
		dfs(u.f);
	}
	out[x] = label;
}
int main()
{
	ll label = 1;
	ll q;
	string s;
	input(q);
	queries.resize(q);
	for (ll i=0; i<q; ++i)
	{
		cin >> s;
		if (s=="Add") queries[i].a = 0;
		else queries[i].a = 1;
		input2(queries[i].b, queries[i].c);
		if (s=="Add") 
		{
			add[queries[i].b].pb(mp(++label, queries[i].c));
		}
		
	}
	dfs(1);
	root = new node(0);
	root->insert(0, 0);
	label  = 1;
	for (ll i=0; i<q; ++i)
	{
		ll a = queries[i].a, b = queries[i].b, c = queries[i].c;
		if (a)
		{
			print(root->xorquery(root_xor[b], in[c], out[c]), '\n');
		}
		else
		{
			++label;
			root->insert(root_xor[label], in[label]);
		}
	}
	return 0;
}

Compilation message

klasika.cpp: In function 'int main()':
klasika.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
klasika.cpp:109:2: note: in expansion of macro 'input'
  109 |  input(q);
      |  ^~~~~
klasika.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
klasika.cpp:116:3: note: in expansion of macro 'input2'
  116 |   input2(queries[i].b, queries[i].c);
      |   ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 3 ms 9072 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9308 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 3 ms 9072 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9308 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 5 ms 10076 KB Output is correct
14 Correct 7 ms 11356 KB Output is correct
15 Correct 8 ms 12800 KB Output is correct
16 Correct 8 ms 13916 KB Output is correct
17 Correct 5 ms 10328 KB Output is correct
18 Correct 6 ms 11356 KB Output is correct
19 Correct 7 ms 12516 KB Output is correct
20 Correct 8 ms 13656 KB Output is correct
21 Correct 4 ms 10076 KB Output is correct
22 Correct 6 ms 11352 KB Output is correct
23 Correct 8 ms 12572 KB Output is correct
24 Correct 9 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 518 ms 127496 KB Output is correct
2 Correct 853 ms 232276 KB Output is correct
3 Correct 1303 ms 331248 KB Output is correct
4 Correct 1576 ms 436148 KB Output is correct
5 Correct 579 ms 126616 KB Output is correct
6 Correct 1045 ms 229960 KB Output is correct
7 Correct 1400 ms 329084 KB Output is correct
8 Correct 1893 ms 428632 KB Output is correct
9 Correct 530 ms 126292 KB Output is correct
10 Correct 883 ms 230620 KB Output is correct
11 Correct 1319 ms 331344 KB Output is correct
12 Correct 1622 ms 430328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 3 ms 9072 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9308 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 5 ms 10076 KB Output is correct
14 Correct 7 ms 11356 KB Output is correct
15 Correct 8 ms 12800 KB Output is correct
16 Correct 8 ms 13916 KB Output is correct
17 Correct 5 ms 10328 KB Output is correct
18 Correct 6 ms 11356 KB Output is correct
19 Correct 7 ms 12516 KB Output is correct
20 Correct 8 ms 13656 KB Output is correct
21 Correct 4 ms 10076 KB Output is correct
22 Correct 6 ms 11352 KB Output is correct
23 Correct 8 ms 12572 KB Output is correct
24 Correct 9 ms 13660 KB Output is correct
25 Correct 518 ms 127496 KB Output is correct
26 Correct 853 ms 232276 KB Output is correct
27 Correct 1303 ms 331248 KB Output is correct
28 Correct 1576 ms 436148 KB Output is correct
29 Correct 579 ms 126616 KB Output is correct
30 Correct 1045 ms 229960 KB Output is correct
31 Correct 1400 ms 329084 KB Output is correct
32 Correct 1893 ms 428632 KB Output is correct
33 Correct 530 ms 126292 KB Output is correct
34 Correct 883 ms 230620 KB Output is correct
35 Correct 1319 ms 331344 KB Output is correct
36 Correct 1622 ms 430328 KB Output is correct
37 Correct 944 ms 129360 KB Output is correct
38 Correct 1381 ms 233640 KB Output is correct
39 Correct 1661 ms 337580 KB Output is correct
40 Correct 1795 ms 436784 KB Output is correct
41 Correct 1040 ms 126908 KB Output is correct
42 Correct 1462 ms 230124 KB Output is correct
43 Correct 1821 ms 329692 KB Output is correct
44 Correct 2090 ms 427936 KB Output is correct
45 Correct 1125 ms 126768 KB Output is correct
46 Correct 1613 ms 230676 KB Output is correct
47 Correct 1827 ms 330288 KB Output is correct
48 Correct 1941 ms 430240 KB Output is correct