Submission #876701

# Submission time Handle Problem Language Result Execution time Memory
876701 2023-11-22T08:42:04 Z huynhyen1609 Experimental Charges (NOI19_charges) C++14
100 / 100
35 ms 10708 KB
#include<bits/stdc++.h>
using namespace std;
#define NAME "hattichdien"
//#define int long long
const int N=2e5;
int n,q,p[N+5],a[N+5];
vector<int>vec[N+5];
int find(int v)
{
    if(p[v]==0)return v;
    return p[v]=find(p[v]);
}
void union_(int u,int v,int c)
{
    int x=u,y=v;
    u=find(u);v=find(v);
    if(u==v)return;
    if(vec[u].size()<vec[v].size())
    {
        swap(u,v);
        swap(x,y);
    }
    p[v]=u;
    for(int i:vec[v])vec[u].push_back(i);
    if(c!=(a[x]^a[y]))for(int i:vec[v])a[i]=1-a[i];
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //freopen(""NAME".inp","r",stdin);
    //freopen(""NAME".out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;++i)
    {
        a[i]=1;
        vec[i].push_back(i);
    }
    while(q--)
    {
        char c;
        int x,y;
        cin>>c>>x>>y;
        if(c=='R')union_(x,y,0);
        if(c=='A')union_(x,y,1);
        if(c=='Q')
        {
            if(find(x)!=find(y))cout<<"?\n";
            else
            {
                if(a[x]^a[y])cout<<"A\n";
                else cout<<"R\n";
            }
        }
    }
}

Compilation message

charges.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 5168 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9176 KB Output is correct
2 Correct 18 ms 9944 KB Output is correct
3 Correct 19 ms 10064 KB Output is correct
4 Correct 19 ms 10192 KB Output is correct
5 Correct 20 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9176 KB Output is correct
2 Correct 22 ms 9384 KB Output is correct
3 Correct 22 ms 9296 KB Output is correct
4 Correct 28 ms 9496 KB Output is correct
5 Correct 35 ms 9616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 8916 KB Output is correct
2 Correct 30 ms 10400 KB Output is correct
3 Correct 22 ms 10456 KB Output is correct
4 Correct 24 ms 10704 KB Output is correct
5 Correct 31 ms 10708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 5168 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 5168 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 18 ms 9176 KB Output is correct
7 Correct 18 ms 9944 KB Output is correct
8 Correct 19 ms 10064 KB Output is correct
9 Correct 19 ms 10192 KB Output is correct
10 Correct 20 ms 10072 KB Output is correct
11 Correct 19 ms 9176 KB Output is correct
12 Correct 22 ms 9384 KB Output is correct
13 Correct 22 ms 9296 KB Output is correct
14 Correct 28 ms 9496 KB Output is correct
15 Correct 35 ms 9616 KB Output is correct
16 Correct 20 ms 8916 KB Output is correct
17 Correct 30 ms 10400 KB Output is correct
18 Correct 22 ms 10456 KB Output is correct
19 Correct 24 ms 10704 KB Output is correct
20 Correct 31 ms 10708 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 1 ms 5212 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 1 ms 5212 KB Output is correct
26 Correct 20 ms 10460 KB Output is correct
27 Correct 21 ms 10496 KB Output is correct
28 Correct 23 ms 10456 KB Output is correct
29 Correct 23 ms 10588 KB Output is correct
30 Correct 22 ms 10584 KB Output is correct