답안 #1039812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039812 2024-07-31T09:38:33 Z 12345678 Inside information (BOI21_servers) C++17
62.5 / 100
3500 ms 40276 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int nx=250005, kx=18, mod=400;
 
int n, k, a[nx], b[nx], idx[nx], cnt[nx], lvl[nx], pa[nx][kx], up[nx], dn[nx], pw[nx], t, in[nx], out[nx], lst, dp[nx], l[nx], r[nx], pts[nx];
char opr[nx];
vector<pair<int, int>> d[nx];
 
void dfs(int u, int p)
{
    lvl[u]=lvl[p]+1;
    in[u]=++t;
    up[u]=p;
    if (pw[u]<pw[p]) up[u]=up[p];
    dn[u]=p;
    if (pw[u]>pw[p]) dn[u]=dn[p];
    pa[u][0]=p;
    for (int i=1; i<kx; i++) pa[u][i]=pa[pa[u][i-1]][i-1];
    for (auto [v, w]:d[u]) if (v!=p) pw[v]=w, dfs(v, u);
    out[u]=t;
}
 
pair<int, int> query1(int idx)
{
    if (in[a[idx]]<=in[b[idx]]&&in[b[idx]]<=out[a[idx]]) return {a[idx], 0};
    int tmp=a[idx];
    for (int i=kx-1; i>=0; i--) if (!(in[pa[tmp][i]]<=in[b[idx]]&&in[b[idx]]<=out[pa[tmp][i]])) tmp=pa[tmp][i];
    if (lvl[up[a[idx]]]>lvl[pa[tmp][0]]) return {-1, 0};
    return {pa[tmp][0], pw[tmp]};
}
 
int query(int i)
{
    auto [u, lst]=query1(i);
    if (u==-1) return 0;
    else
    {
        if (u==b[i]&&lst<=cnt[i]) return 1;
        else if (u==b[i]&&lst>cnt[i]) return 0;
        else
        {
            int vl=pw[b[i]], tmp=b[i];
            if (lvl[dn[b[i]]]>lvl[u]||pw[b[i]]>cnt[i]) return 0;
            else
            {
                for (int j=kx-1; j>=0; j--) if (lvl[pa[tmp][j]]>lvl[u]) tmp=pa[tmp][j];
                if (lst<pw[tmp]) return 1;
                else return 0;
            }
        }
    }
    return 0;
}
 
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) pts[i]=i, dp[i]=1;
    for (int i=1; i<n+k; i++)
    {
        cin>>opr[i];
        cnt[i]=cnt[i-1];
        if (opr[i]=='S') cin>>a[i]>>b[i], idx[++cnt[i]]=i, d[a[i]].push_back({b[i], cnt[i]}), d[b[i]].push_back({a[i], cnt[i]}), l[cnt[i]+n]=pts[a[i]], r[cnt[i]+n]=pts[b[i]], pts[a[i]]=pts[b[i]]=cnt[i]+n;
        if (opr[i]=='Q') cin>>b[i]>>a[i];
        if (opr[i]=='C') cin>>a[i];
    }
    dfs(1, 1);
    for (int i=1; i<n+k; i++)
    {
        if (opr[i]=='S')
        {
            if ((cnt[i]%mod)==0)
            {
                lst=cnt[i];
                for (int j=1; j<=n+cnt[j]; j++) dp[j]=1;
                for (int j=n+cnt[i]; j>=n+1; j--) dp[l[j]]+=dp[j], dp[r[j]]+=dp[j];
                lst=cnt[i];
            }
        }
        if (opr[i]=='Q') cout<<(query(i)?"yes\n":"no\n");
        if (opr[i]=='C') 
        {
            int tmp=dp[a[i]];
            for (int j=lst+1; j<=cnt[i]; j++) 
            {
                int f=1;
                b[i]=a[idx[j]];
                if (!query(i)) f=0;
                b[i]=b[idx[j]];
                if (!query(i)) f=0;
                tmp+=f;
            }
            cout<<tmp<<'\n';
        }
    }
}

Compilation message

servers.cpp: In function 'int query(int)':
servers.cpp:44:17: warning: unused variable 'vl' [-Wunused-variable]
   44 |             int vl=pw[b[i]], tmp=b[i];
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 17756 KB Output is correct
2 Correct 30 ms 16216 KB Output is correct
3 Correct 36 ms 16208 KB Output is correct
4 Correct 35 ms 18224 KB Output is correct
5 Correct 28 ms 11608 KB Output is correct
6 Correct 39 ms 14220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 17756 KB Output is correct
2 Correct 30 ms 16216 KB Output is correct
3 Correct 36 ms 16208 KB Output is correct
4 Correct 35 ms 18224 KB Output is correct
5 Correct 28 ms 11608 KB Output is correct
6 Correct 39 ms 14220 KB Output is correct
7 Correct 69 ms 17780 KB Output is correct
8 Incorrect 1628 ms 18036 KB Extra information in the output file
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 17752 KB Output is correct
2 Correct 208 ms 30496 KB Output is correct
3 Correct 181 ms 32196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 17752 KB Output is correct
2 Correct 208 ms 30496 KB Output is correct
3 Correct 181 ms 32196 KB Output is correct
4 Correct 84 ms 17792 KB Output is correct
5 Correct 1155 ms 31684 KB Output is correct
6 Correct 1593 ms 33736 KB Output is correct
7 Correct 3353 ms 33580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 17756 KB Output is correct
2 Correct 145 ms 39972 KB Output is correct
3 Correct 162 ms 39924 KB Output is correct
4 Correct 161 ms 40016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 17756 KB Output is correct
2 Correct 145 ms 39972 KB Output is correct
3 Correct 162 ms 39924 KB Output is correct
4 Correct 161 ms 40016 KB Output is correct
5 Correct 42 ms 17888 KB Output is correct
6 Correct 2442 ms 39884 KB Output is correct
7 Correct 1291 ms 40016 KB Output is correct
8 Execution timed out 3604 ms 39968 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 17744 KB Output is correct
2 Correct 122 ms 33328 KB Output is correct
3 Correct 139 ms 33840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 17744 KB Output is correct
2 Correct 122 ms 33328 KB Output is correct
3 Correct 139 ms 33840 KB Output is correct
4 Correct 68 ms 17864 KB Output is correct
5 Correct 3483 ms 33408 KB Output is correct
6 Correct 1746 ms 33912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 17752 KB Output is correct
2 Correct 158 ms 40040 KB Output is correct
3 Correct 165 ms 39984 KB Output is correct
4 Correct 147 ms 40096 KB Output is correct
5 Correct 23 ms 17864 KB Output is correct
6 Correct 111 ms 33420 KB Output is correct
7 Correct 138 ms 33876 KB Output is correct
8 Correct 156 ms 34388 KB Output is correct
9 Correct 163 ms 34336 KB Output is correct
10 Correct 168 ms 37996 KB Output is correct
11 Correct 161 ms 37456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 17752 KB Output is correct
2 Correct 158 ms 40040 KB Output is correct
3 Correct 165 ms 39984 KB Output is correct
4 Correct 147 ms 40096 KB Output is correct
5 Correct 23 ms 17864 KB Output is correct
6 Correct 111 ms 33420 KB Output is correct
7 Correct 138 ms 33876 KB Output is correct
8 Correct 156 ms 34388 KB Output is correct
9 Correct 163 ms 34336 KB Output is correct
10 Correct 168 ms 37996 KB Output is correct
11 Correct 161 ms 37456 KB Output is correct
12 Correct 42 ms 17756 KB Output is correct
13 Correct 2470 ms 40016 KB Output is correct
14 Correct 1341 ms 40140 KB Output is correct
15 Execution timed out 3575 ms 39744 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 17704 KB Output is correct
2 Correct 38 ms 18260 KB Output is correct
3 Correct 37 ms 17976 KB Output is correct
4 Correct 31 ms 18012 KB Output is correct
5 Correct 27 ms 18264 KB Output is correct
6 Correct 39 ms 18008 KB Output is correct
7 Correct 30 ms 17756 KB Output is correct
8 Correct 162 ms 33388 KB Output is correct
9 Correct 140 ms 33476 KB Output is correct
10 Correct 20 ms 17752 KB Output is correct
11 Correct 145 ms 40020 KB Output is correct
12 Correct 147 ms 40276 KB Output is correct
13 Correct 135 ms 40020 KB Output is correct
14 Correct 24 ms 17788 KB Output is correct
15 Correct 113 ms 33360 KB Output is correct
16 Correct 138 ms 33940 KB Output is correct
17 Correct 144 ms 34132 KB Output is correct
18 Correct 149 ms 34640 KB Output is correct
19 Correct 147 ms 37968 KB Output is correct
20 Correct 166 ms 37588 KB Output is correct
21 Correct 140 ms 33472 KB Output is correct
22 Correct 130 ms 33568 KB Output is correct
23 Correct 136 ms 33876 KB Output is correct
24 Correct 131 ms 33872 KB Output is correct
25 Correct 152 ms 34984 KB Output is correct
26 Correct 136 ms 33364 KB Output is correct
27 Correct 128 ms 33152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 17704 KB Output is correct
2 Correct 38 ms 18260 KB Output is correct
3 Correct 37 ms 17976 KB Output is correct
4 Correct 31 ms 18012 KB Output is correct
5 Correct 27 ms 18264 KB Output is correct
6 Correct 39 ms 18008 KB Output is correct
7 Correct 30 ms 17756 KB Output is correct
8 Correct 162 ms 33388 KB Output is correct
9 Correct 140 ms 33476 KB Output is correct
10 Correct 20 ms 17752 KB Output is correct
11 Correct 145 ms 40020 KB Output is correct
12 Correct 147 ms 40276 KB Output is correct
13 Correct 135 ms 40020 KB Output is correct
14 Correct 24 ms 17788 KB Output is correct
15 Correct 113 ms 33360 KB Output is correct
16 Correct 138 ms 33940 KB Output is correct
17 Correct 144 ms 34132 KB Output is correct
18 Correct 149 ms 34640 KB Output is correct
19 Correct 147 ms 37968 KB Output is correct
20 Correct 166 ms 37588 KB Output is correct
21 Correct 140 ms 33472 KB Output is correct
22 Correct 130 ms 33568 KB Output is correct
23 Correct 136 ms 33876 KB Output is correct
24 Correct 131 ms 33872 KB Output is correct
25 Correct 152 ms 34984 KB Output is correct
26 Correct 136 ms 33364 KB Output is correct
27 Correct 128 ms 33152 KB Output is correct
28 Correct 67 ms 17756 KB Output is correct
29 Incorrect 1559 ms 17964 KB Extra information in the output file
30 Halted 0 ms 0 KB -