답안 #1040404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040404 2024-08-01T03:29:20 Z 12345678 Inside information (BOI21_servers) C++17
80 / 100
2076 ms 45908 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int nx=250005, kx=18, mod=200;
 
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;
            }
        }
    }
}
 
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)
            {
                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:47:17: warning: unused variable 'vl' [-Wunused-variable]
   47 |             int vl=pw[b[i]], tmp=b[i];
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19800 KB Output is correct
2 Correct 26 ms 19984 KB Output is correct
3 Correct 32 ms 20060 KB Output is correct
4 Correct 27 ms 20060 KB Output is correct
5 Correct 23 ms 20312 KB Output is correct
6 Correct 35 ms 20048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19800 KB Output is correct
2 Correct 26 ms 19984 KB Output is correct
3 Correct 32 ms 20060 KB Output is correct
4 Correct 27 ms 20060 KB Output is correct
5 Correct 23 ms 20312 KB Output is correct
6 Correct 35 ms 20048 KB Output is correct
7 Correct 55 ms 19824 KB Output is correct
8 Incorrect 695 ms 20052 KB Extra information in the output file
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19804 KB Output is correct
2 Correct 179 ms 35140 KB Output is correct
3 Correct 181 ms 34924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19804 KB Output is correct
2 Correct 179 ms 35140 KB Output is correct
3 Correct 181 ms 34924 KB Output is correct
4 Correct 69 ms 19804 KB Output is correct
5 Correct 585 ms 35024 KB Output is correct
6 Correct 772 ms 35272 KB Output is correct
7 Correct 1513 ms 35268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19804 KB Output is correct
2 Correct 176 ms 43512 KB Output is correct
3 Correct 179 ms 43452 KB Output is correct
4 Correct 166 ms 43348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19804 KB Output is correct
2 Correct 176 ms 43512 KB Output is correct
3 Correct 179 ms 43452 KB Output is correct
4 Correct 166 ms 43348 KB Output is correct
5 Correct 37 ms 19804 KB Output is correct
6 Correct 1202 ms 43348 KB Output is correct
7 Correct 650 ms 43608 KB Output is correct
8 Correct 2020 ms 43364 KB Output is correct
9 Correct 2033 ms 45908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19800 KB Output is correct
2 Correct 132 ms 34900 KB Output is correct
3 Correct 178 ms 35560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19800 KB Output is correct
2 Correct 132 ms 34900 KB Output is correct
3 Correct 178 ms 35560 KB Output is correct
4 Correct 52 ms 19812 KB Output is correct
5 Correct 1586 ms 34964 KB Output is correct
6 Correct 848 ms 35412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19804 KB Output is correct
2 Correct 188 ms 43600 KB Output is correct
3 Correct 174 ms 43500 KB Output is correct
4 Correct 168 ms 43456 KB Output is correct
5 Correct 20 ms 19804 KB Output is correct
6 Correct 135 ms 35056 KB Output is correct
7 Correct 174 ms 35408 KB Output is correct
8 Correct 202 ms 35920 KB Output is correct
9 Correct 182 ms 35928 KB Output is correct
10 Correct 175 ms 40272 KB Output is correct
11 Correct 176 ms 39556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19804 KB Output is correct
2 Correct 188 ms 43600 KB Output is correct
3 Correct 174 ms 43500 KB Output is correct
4 Correct 168 ms 43456 KB Output is correct
5 Correct 20 ms 19804 KB Output is correct
6 Correct 135 ms 35056 KB Output is correct
7 Correct 174 ms 35408 KB Output is correct
8 Correct 202 ms 35920 KB Output is correct
9 Correct 182 ms 35928 KB Output is correct
10 Correct 175 ms 40272 KB Output is correct
11 Correct 176 ms 39556 KB Output is correct
12 Correct 33 ms 19924 KB Output is correct
13 Correct 1161 ms 43384 KB Output is correct
14 Correct 640 ms 43352 KB Output is correct
15 Correct 2076 ms 43348 KB Output is correct
16 Correct 2017 ms 45840 KB Output is correct
17 Correct 54 ms 20816 KB Output is correct
18 Correct 1562 ms 37880 KB Output is correct
19 Correct 856 ms 38224 KB Output is correct
20 Correct 1455 ms 38840 KB Output is correct
21 Correct 888 ms 38792 KB Output is correct
22 Correct 1719 ms 42092 KB Output is correct
23 Correct 1492 ms 42080 KB Output is correct
24 Correct 423 ms 42064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19940 KB Output is correct
2 Correct 25 ms 20052 KB Output is correct
3 Correct 30 ms 20048 KB Output is correct
4 Correct 28 ms 20048 KB Output is correct
5 Correct 28 ms 20316 KB Output is correct
6 Correct 39 ms 20072 KB Output is correct
7 Correct 29 ms 19800 KB Output is correct
8 Correct 178 ms 35008 KB Output is correct
9 Correct 182 ms 35012 KB Output is correct
10 Correct 16 ms 19800 KB Output is correct
11 Correct 192 ms 43600 KB Output is correct
12 Correct 180 ms 43600 KB Output is correct
13 Correct 176 ms 43344 KB Output is correct
14 Correct 21 ms 19800 KB Output is correct
15 Correct 129 ms 34896 KB Output is correct
16 Correct 177 ms 35408 KB Output is correct
17 Correct 181 ms 35856 KB Output is correct
18 Correct 187 ms 35924 KB Output is correct
19 Correct 186 ms 40272 KB Output is correct
20 Correct 176 ms 39616 KB Output is correct
21 Correct 178 ms 34876 KB Output is correct
22 Correct 174 ms 35068 KB Output is correct
23 Correct 164 ms 35412 KB Output is correct
24 Correct 169 ms 35408 KB Output is correct
25 Correct 199 ms 37164 KB Output is correct
26 Correct 160 ms 34788 KB Output is correct
27 Correct 170 ms 34896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19940 KB Output is correct
2 Correct 25 ms 20052 KB Output is correct
3 Correct 30 ms 20048 KB Output is correct
4 Correct 28 ms 20048 KB Output is correct
5 Correct 28 ms 20316 KB Output is correct
6 Correct 39 ms 20072 KB Output is correct
7 Correct 29 ms 19800 KB Output is correct
8 Correct 178 ms 35008 KB Output is correct
9 Correct 182 ms 35012 KB Output is correct
10 Correct 16 ms 19800 KB Output is correct
11 Correct 192 ms 43600 KB Output is correct
12 Correct 180 ms 43600 KB Output is correct
13 Correct 176 ms 43344 KB Output is correct
14 Correct 21 ms 19800 KB Output is correct
15 Correct 129 ms 34896 KB Output is correct
16 Correct 177 ms 35408 KB Output is correct
17 Correct 181 ms 35856 KB Output is correct
18 Correct 187 ms 35924 KB Output is correct
19 Correct 186 ms 40272 KB Output is correct
20 Correct 176 ms 39616 KB Output is correct
21 Correct 178 ms 34876 KB Output is correct
22 Correct 174 ms 35068 KB Output is correct
23 Correct 164 ms 35412 KB Output is correct
24 Correct 169 ms 35408 KB Output is correct
25 Correct 199 ms 37164 KB Output is correct
26 Correct 160 ms 34788 KB Output is correct
27 Correct 170 ms 34896 KB Output is correct
28 Correct 54 ms 19920 KB Output is correct
29 Incorrect 694 ms 20052 KB Extra information in the output file
30 Halted 0 ms 0 KB -