Submission #863527

# Submission time Handle Problem Language Result Execution time Memory
863527 2023-10-20T14:06:32 Z HossamHero7 Inside information (BOI21_servers) C++14
10 / 100
101 ms 3388 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
    int n,q;
    cin>>n>>q;
    if(n <= 4000){
        vector<vector<bool>> vis(n+1,vector<bool>(n+1));
        for(int i=1;i<=n;i++) vis[i][i] = 1;
        vector<int> cnt(n+1,1);
        for(int qq=0;qq<n+q-1;qq++){
            char c;
            int a,b;
            cin>>c>>a;
            if(c != 'C') cin>>b;
            if(c == 'S'){
                for(int j=1;j<=n;j++){
                    cnt[j] += vis[a][j] ^ vis[b][j];
                    vis[a][j] = vis[a][j] | vis[b][j];
                }
                vis[b] = vis[a];
            }
            else if(c == 'C') cout<<cnt[a]<<endl;
            else cout<<(vis[a][b] ? "yes" : "no")<<endl;
        }
    }
    else {
        vector<bool> vis(n+1);
        vis[1] = 1;
        vector<int> idx(n+1);
        int cnt = 1;
        idx[1] = 0;
        for(int qq=0;qq<n+q-1;qq++){
            char c;
            int a,b;
            cin>>c>>a;
            if(c != 'C') cin>>b;
            if(c == 'S'){
                vis[max(a,b)] = 1;
                idx[max(a,b)] = cnt;
                cnt ++;
            }
            else if(c == 'C'){
                if(!vis[a]) cout<<1<<endl;
                else cout<<cnt - idx[a] + (a != 1)<<endl;
            }
            else {
                if(a == b) cout<<"yes"<<endl;
                else {
                    if(min(a,b) == 1 && vis[a] && vis[b]) cout<<"yes"<<endl;
                    else if(vis[a] && vis[b] && idx[a] > idx[b]) cout<<"yes"<<endl;
                    else cout<<"no"<<endl;
                }
            }

        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Correct 83 ms 2928 KB Output is correct
3 Correct 89 ms 2900 KB Output is correct
4 Correct 83 ms 2892 KB Output is correct
5 Correct 81 ms 2892 KB Output is correct
6 Correct 86 ms 2956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Correct 83 ms 2928 KB Output is correct
3 Correct 89 ms 2900 KB Output is correct
4 Correct 83 ms 2892 KB Output is correct
5 Correct 81 ms 2892 KB Output is correct
6 Correct 86 ms 2956 KB Output is correct
7 Correct 16 ms 600 KB Output is correct
8 Correct 101 ms 2936 KB Output is correct
9 Correct 80 ms 2896 KB Output is correct
10 Correct 84 ms 2896 KB Output is correct
11 Correct 84 ms 2888 KB Output is correct
12 Correct 80 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 856 KB Output is correct
2 Correct 36 ms 1288 KB Output is correct
3 Correct 36 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 856 KB Output is correct
2 Correct 36 ms 1288 KB Output is correct
3 Correct 36 ms 1256 KB Output is correct
4 Correct 15 ms 800 KB Output is correct
5 Correct 36 ms 1368 KB Output is correct
6 Correct 28 ms 3184 KB Output is correct
7 Correct 29 ms 3388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Incorrect 47 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Incorrect 47 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 604 KB Output is correct
2 Incorrect 38 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 604 KB Output is correct
2 Incorrect 38 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Incorrect 39 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Incorrect 39 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 84 ms 2896 KB Output is correct
3 Correct 82 ms 2880 KB Output is correct
4 Correct 93 ms 2924 KB Output is correct
5 Correct 83 ms 2804 KB Output is correct
6 Correct 83 ms 2896 KB Output is correct
7 Correct 16 ms 604 KB Output is correct
8 Correct 40 ms 1116 KB Output is correct
9 Correct 37 ms 1372 KB Output is correct
10 Correct 16 ms 600 KB Output is correct
11 Incorrect 38 ms 1196 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 84 ms 2896 KB Output is correct
3 Correct 82 ms 2880 KB Output is correct
4 Correct 93 ms 2924 KB Output is correct
5 Correct 83 ms 2804 KB Output is correct
6 Correct 83 ms 2896 KB Output is correct
7 Correct 16 ms 604 KB Output is correct
8 Correct 40 ms 1116 KB Output is correct
9 Correct 37 ms 1372 KB Output is correct
10 Correct 16 ms 600 KB Output is correct
11 Incorrect 38 ms 1196 KB Output isn't correct
12 Halted 0 ms 0 KB -