답안 #863518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863518 2023-10-20T13:54:51 Z HossamHero7 Inside information (BOI21_servers) C++14
7.5 / 100
102 ms 3032 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(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 604 KB Output is correct
2 Correct 84 ms 2888 KB Output is correct
3 Correct 89 ms 2896 KB Output is correct
4 Correct 87 ms 2788 KB Output is correct
5 Correct 86 ms 2880 KB Output is correct
6 Correct 83 ms 2896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 604 KB Output is correct
2 Correct 84 ms 2888 KB Output is correct
3 Correct 89 ms 2896 KB Output is correct
4 Correct 87 ms 2788 KB Output is correct
5 Correct 86 ms 2880 KB Output is correct
6 Correct 83 ms 2896 KB Output is correct
7 Correct 18 ms 604 KB Output is correct
8 Correct 92 ms 2964 KB Output is correct
9 Correct 82 ms 2896 KB Output is correct
10 Correct 85 ms 2816 KB Output is correct
11 Correct 81 ms 2888 KB Output is correct
12 Correct 82 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 856 KB Output is correct
2 Correct 37 ms 1168 KB Output is correct
3 Correct 37 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 856 KB Output is correct
2 Correct 37 ms 1168 KB Output is correct
3 Correct 37 ms 1112 KB Output is correct
4 Correct 18 ms 600 KB Output is correct
5 Incorrect 36 ms 1364 KB Extra information in the output file
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 600 KB Output is correct
2 Incorrect 44 ms 1220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 600 KB Output is correct
2 Incorrect 44 ms 1220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 604 KB Output is correct
2 Incorrect 38 ms 1372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 604 KB Output is correct
2 Incorrect 38 ms 1372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 604 KB Output is correct
2 Incorrect 40 ms 1316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 604 KB Output is correct
2 Incorrect 40 ms 1316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 676 KB Output is correct
2 Correct 95 ms 2904 KB Output is correct
3 Correct 85 ms 2976 KB Output is correct
4 Correct 91 ms 2800 KB Output is correct
5 Correct 89 ms 2748 KB Output is correct
6 Correct 102 ms 3032 KB Output is correct
7 Correct 18 ms 600 KB Output is correct
8 Correct 38 ms 1268 KB Output is correct
9 Correct 47 ms 1108 KB Output is correct
10 Correct 21 ms 604 KB Output is correct
11 Incorrect 43 ms 1268 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 676 KB Output is correct
2 Correct 95 ms 2904 KB Output is correct
3 Correct 85 ms 2976 KB Output is correct
4 Correct 91 ms 2800 KB Output is correct
5 Correct 89 ms 2748 KB Output is correct
6 Correct 102 ms 3032 KB Output is correct
7 Correct 18 ms 600 KB Output is correct
8 Correct 38 ms 1268 KB Output is correct
9 Correct 47 ms 1108 KB Output is correct
10 Correct 21 ms 604 KB Output is correct
11 Incorrect 43 ms 1268 KB Output isn't correct
12 Halted 0 ms 0 KB -