답안 #903363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903363 2024-01-11T07:19:07 Z simona1230 Inside information (BOI21_servers) C++17
0 / 100
171 ms 5796 KB
#include <bits/stdc++.h>

using namespace std;

int n,k;
int in[4001][4001];
char c[120001];
int x[120001],y[120001];

void read()
{
    cin>>n>>k;
    for(int i=1;i<=n+k-1;i++)
    {
        cin>>c[i]>>x[i];
        if(c[i]!='C')cin>>y[i];
    }
}

void slow()
{
    for(int i=1;i<=n;i++)
        in[i][i]=1;
    for(int i=1;i<=n+k-1;i++)
    {
        if(c[i]=='S')
        {
            for(int j=1;j<=n;j++)
            {
                in[x[i]][j]=in[y[i]][j]=max(in[x[i]][j],in[y[i]][j]);
            }
        }
        if(c[i]=='C')
        {
            int cnt=0;
            for(int j=1;j<=n;j++)
                cnt+=in[j][x[i]];
            cout<<cnt<<endl;
        }
        if(c[i]=='Q')
        {
            if(in[x[i]][y[i]])cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
}


int t[120001];
void subt2()
{
    t[1]=1;
    int sec=2;
    for(int i=1;i<=n+k-1;i++)
    {
        if(c[i]=='S')
        {
            t[max(x[i],y[i])]=sec++;
        }

        if(c[i]=='Q')
        {
            if(t[y[i]]&&t[y[i]]<=t[x[i]]||x[i]==1&&t[y[i]]||y[i]==1&&t[x[i]]||x[i]==y[i])cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }

        if(c[i]=='C')
        {
            if(t[x[i]]==0)cout<<1<<endl;
            else if(x[i]==1)cout<<sec-1<<endl;
            else cout<<sec-t[x[i]]+1<<endl;
        }
    }
}

int inc[120001],de[120001];
int find_inc(int ver)
{
    cout<<ver<<endl;
    if(ver==inc[ver])return ver;
    return inc[ver]=find_inc(inc[ver]);
}
int find_de(int ver)
{
    if(ver==de[ver])return ver;
    return de[ver]=find_de(de[ver]);
}

void subt3()
{
    int sec=1;
    for(int i=1;i<=n+k-1;i++)
    {
        if(c[i]=='S')
        {
            if(y[i]<x[i])swap(x[i],y[i]);
            t[x[i]]=sec++;
            inc[x[i]]=de[x[i]]=x[i];
            if(t[x[i]-1])inc[x[i]-1]=x[i];
            if(t[x[i]+1])de[x[i]+1]=x[i];
        }
        if(c[i]=='Q')
        {
            int ver=x[i];
            if(y[i]>x[i])
            {
                if(!t[ver])
                {
                    cout<<"no"<<endl;
                    continue;
                }
                ver=find_inc(ver);
                if(ver+1>=y[i])cout<<"yes"<<endl;
                else cout<<"no"<<endl;
            }
            else if(x[i]>y[i])
            {
                if(!t[ver-1])
                {
                    cout<<"no"<<endl;
                    continue;
                }
                ver=find_de(ver-1);
                if(ver<=y[i])cout<<"y[i]es"<<endl;
                else cout<<"no"<<endl;
            }
            else cout<<"yes"<<endl;
        }
        if(c[i]=='C')
        {
            int cnt=0;
            if(x[i]!=n&&t[x[i]])
            {
                cout<<"! "<<x[i]<<endl;
                cnt+=find_inc(x[i])-x[i]+1;
            }
            if(x[i]!=1&&t[x[i]-1])
            {
                cout<<"!! "<<x[i]-1<<endl;
                cnt+=x[i]-find_de(x[i]-1);
            }
            cout<<cnt<<endl;
        }
    }
}

bool sbt2,sbt3;
void check()
{
    sbt2=1;
    for(int i=1;i<=n+k-1;i++)
    {
        if(c[i]=='S'&&min(x[i],y[i])!=1)sbt2=0;
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	read();
	check();
	if(n<=4000)slow();
    else if(sbt2)subt2();
    else subt3();

	return 0;
}

Compilation message

servers.cpp: In function 'void subt2()':
servers.cpp:63:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   63 |             if(t[y[i]]&&t[y[i]]<=t[x[i]]||x[i]==1&&t[y[i]]||y[i]==1&&t[x[i]]||x[i]==y[i])cout<<"yes"<<endl;
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~
servers.cpp:63:68: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   63 |             if(t[y[i]]&&t[y[i]]<=t[x[i]]||x[i]==1&&t[y[i]]||y[i]==1&&t[x[i]]||x[i]==y[i])cout<<"yes"<<endl;
      |                                                             ~~~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 137 ms 5796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 137 ms 5796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 5716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 5716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 145 ms 4888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 145 ms 4888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 164 ms 4884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 164 ms 4884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 171 ms 4756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 171 ms 4756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 148 ms 4660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 148 ms 4660 KB Output isn't correct
2 Halted 0 ms 0 KB -