Submission #209435

# Submission time Handle Problem Language Result Execution time Memory
209435 2020-03-14T07:54:46 Z model_code Experimental Charges (NOI19_charges) C++17
100 / 100
47 ms 1660 KB
#include <bits/stdc++.h>

using namespace std;

pair<int,bool> p[100009];

pair<int,bool> fp(int x){
	if(p[x].first==x)return make_pair(x, 0);
	pair<int,bool> xpar = fp(p[x].first);
	return p[x] = make_pair(xpar.first, xpar.second^p[x].second);
}

void mg(int x,int y,bool r){
	pair<int,bool> xpar = fp(x), ypar = fp(y);
	if (xpar.first == ypar.first) return;
	p[xpar.first]= make_pair(ypar.first, r^xpar.second^ypar.second); 
}

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for (int i = 0; i < n; i++) p[i] = make_pair(i, 0);
	for (int i = 0; i < q; i++) {
		char t;
		int a,b;
		scanf(" %c%d%d",&t,&a,&b);a--;b--;
		if (t=='Q') {
			pair<int,bool> apar = fp(a), bpar = fp(b);
			if (apar.first !=bpar.first) puts("?");
			else {
				puts((apar.second != bpar.second)?"A":"R");
			}
		}
		else mg(a,b,t=='A');
	}
}

Compilation message

charges.cpp: In function 'int main()':
charges.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
charges.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d%d",&t,&a,&b);a--;b--;
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1144 KB Output is correct
2 Correct 37 ms 1144 KB Output is correct
3 Correct 40 ms 1144 KB Output is correct
4 Correct 40 ms 1016 KB Output is correct
5 Correct 41 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1144 KB Output is correct
2 Correct 44 ms 1144 KB Output is correct
3 Correct 45 ms 1404 KB Output is correct
4 Correct 46 ms 1212 KB Output is correct
5 Correct 47 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1660 KB Output is correct
2 Correct 41 ms 1272 KB Output is correct
3 Correct 42 ms 1016 KB Output is correct
4 Correct 45 ms 1144 KB Output is correct
5 Correct 43 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 37 ms 1144 KB Output is correct
7 Correct 37 ms 1144 KB Output is correct
8 Correct 40 ms 1144 KB Output is correct
9 Correct 40 ms 1016 KB Output is correct
10 Correct 41 ms 1144 KB Output is correct
11 Correct 43 ms 1144 KB Output is correct
12 Correct 44 ms 1144 KB Output is correct
13 Correct 45 ms 1404 KB Output is correct
14 Correct 46 ms 1212 KB Output is correct
15 Correct 47 ms 1272 KB Output is correct
16 Correct 39 ms 1660 KB Output is correct
17 Correct 41 ms 1272 KB Output is correct
18 Correct 42 ms 1016 KB Output is correct
19 Correct 45 ms 1144 KB Output is correct
20 Correct 43 ms 1144 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 6 ms 256 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 44 ms 1144 KB Output is correct
27 Correct 46 ms 1144 KB Output is correct
28 Correct 47 ms 1144 KB Output is correct
29 Correct 42 ms 1144 KB Output is correct
30 Correct 42 ms 1144 KB Output is correct