Submission #863517

# Submission time Handle Problem Language Result Execution time Memory
863517 2023-10-20T13:53:21 Z HossamHero7 Inside information (BOI21_servers) C++14
5 / 100
89 ms 3000 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') cout<<cnt - idx[a] + (a != 1);
            else {
                if(a == 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 16 ms 604 KB Output is correct
2 Correct 85 ms 2944 KB Output is correct
3 Correct 89 ms 2880 KB Output is correct
4 Correct 85 ms 2908 KB Output is correct
5 Correct 82 ms 2892 KB Output is correct
6 Correct 85 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 604 KB Output is correct
2 Correct 85 ms 2944 KB Output is correct
3 Correct 89 ms 2880 KB Output is correct
4 Correct 85 ms 2908 KB Output is correct
5 Correct 82 ms 2892 KB Output is correct
6 Correct 85 ms 2844 KB Output is correct
7 Correct 16 ms 604 KB Output is correct
8 Correct 80 ms 2812 KB Output is correct
9 Correct 80 ms 2900 KB Output is correct
10 Correct 81 ms 2712 KB Output is correct
11 Correct 82 ms 2892 KB Output is correct
12 Correct 85 ms 3000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 604 KB Output is correct
2 Incorrect 38 ms 1360 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 1360 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 600 KB Output is correct
2 Incorrect 41 ms 1112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 600 KB Output is correct
2 Incorrect 41 ms 1112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 804 KB Output is correct
2 Incorrect 37 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 804 KB Output is correct
2 Incorrect 37 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 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 16 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 16 ms 604 KB Output is correct
2 Correct 88 ms 2928 KB Output is correct
3 Correct 84 ms 2952 KB Output is correct
4 Correct 83 ms 2768 KB Output is correct
5 Correct 82 ms 2888 KB Output is correct
6 Correct 82 ms 2900 KB Output is correct
7 Correct 16 ms 600 KB Output is correct
8 Incorrect 40 ms 1112 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 604 KB Output is correct
2 Correct 88 ms 2928 KB Output is correct
3 Correct 84 ms 2952 KB Output is correct
4 Correct 83 ms 2768 KB Output is correct
5 Correct 82 ms 2888 KB Output is correct
6 Correct 82 ms 2900 KB Output is correct
7 Correct 16 ms 600 KB Output is correct
8 Incorrect 40 ms 1112 KB Output isn't correct
9 Halted 0 ms 0 KB -