This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include<bits/stdc++.h>
using ll = long long int;
// #define INT_MAX = 1e18;
using namespace std;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define printvec(vec) {for(ll i=0;i<vec.size();i++) cout<<vec[i]<<" "; cout<<endl;}
#define inputvec(vec,n) for(ll i=0;i<n;i++){ ll x; cin>>x; vec.pb(x);};
#define inputvecpp(vec,n) for(ll i=0;i<n;i++){ ll x; ll y;cin>>x; cin >> y; vec.pb({x,y});};
#define f first
#define s second
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
ll minv(vector<ll> v){
if (v.size() == 0) return 0;
ll mn = v[0];
for (ll i = 0; i<v.size(); i++){
mn = min(mn, v[i]);
}
return mn;}
ll maxv(vector<ll> v){
if (v.size() == 0) return 0;
ll mn = v[0];
for (ll i = 0; i<v.size(); i++){
mn = max(mn, v[i]);
}
return mn;}
ll sumv(vector<ll> v){
if (v.size() == 0) return 0;
ll mn = 0;
for (ll i = 0; i<v.size(); i++){
mn+= v[i];
}
return mn;}
// ll n;
// void build(vll &a, vll &s, ll i = 0, ll l = 0, ll r = (n-1)){
// if(l == r) s[i] = a[l];
// else{
// int mid = (l+r)/2;
// build(a,s,i*2+1, l, mid);
// build(a,s,i*2+2, mid+1, r);
// s[i] = s[i*2+1] + s[i*2+2];
// }
// }
// void update(vll &v, vll &s, ll id, ll val, ll l = 0, ll r = n-1, ll i = 0 ){
// if(id>r or id<l) return;
// if(l == r) {
// if(l == id) {
// s[i] = val;
// v[id] = val;
// }
// return;
// }
// int mid = (l+r)/2;
// update(v, s, id, val, l, mid, i*2+1);
// update(v, s,id, val, mid+1, r, i*2+2);
// s[i] = s[i*2+1]+s[i*2+2];}
// ll query(vll &v, vll &s, ll L, ll R, ll l = 0, ll r = n-1, ll i = 0){
// if (l>=L and r<=R) return s[i];
// if (l>R or r<L) return 0;
// int mid = (l+r)/2;
// return query(v, s, L,R,l,mid, i*2+1)+query(v, s, L,R,mid+1,r, i*2+2);}
// // build(v,s);
// // query(v, s, --b,--c);
// // update(v, s, --b, c)
ll maxdpv(vll v){
ll x = v.size();
vll dp(x);
dp[0] = v[0];
dp[1] = v[1];
for (ll i = 2; i<x; i++){
dp[i] = max(dp[i-1], dp[i-2] + v[i]);
}
return maxv(dp);
}
void test_case(){
ll n,q;
cin >> n >> q;
vll v(n, -1);
for (ll i = 0; i<q; i++){
char a;
cin >> a;
ll p,q;
cin >> p >> q;
--p;
--q;
if (a == 'Q'){
if (v[p] == -1 || v[q] == -1){
cout << "?" << endl;
}
else if ((v[p] + v[q])%2 == 0) cout << "R" << endl;
else cout << "A" << endl;
}
else{
if (a == 'A'){
if (v[p] == -1 && v[q] == -1){
v[p] = 0;
v[q] = 1;
}
else if (v[p] == -1){
v[p] = 1-v[q]%2;
}
else if (v[q] == -1){
v[q] = 1-v[p]%2;
}
}
else{
if (v[p] == -1 && v[q] == -1){
v[p] = 1;
v[q] = 1;
}
else if (v[p] == -1){
v[p] = v[q];
}
else if (v[q] == -1){
v[q] = v[p];
}
}
}
}
}
int main(){
// ll t;
// cin >> t;
// for (ll i = 0; i<t-1; i++){
// test_case();
// }
test_case();
return 0;
}
Compilation message (stderr)
charges.cpp: In function 'll minv(std::vector<long long int>)':
charges.cpp:20:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (ll i = 0; i<v.size(); i++){
| ~^~~~~~~~~
charges.cpp: In function 'll maxv(std::vector<long long int>)':
charges.cpp:27:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (ll i = 0; i<v.size(); i++){
| ~^~~~~~~~~
charges.cpp: In function 'll sumv(std::vector<long long int>)':
charges.cpp:34:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (ll i = 0; i<v.size(); i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |