QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89907#5110. Splitstream_skb_#RE 2ms3400kbC++202.5kb2023-03-21 19:17:562023-03-21 19:17:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-21 19:17:59]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3400kb
  • [2023-03-21 19:17:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
vector<int> inp;
vector<vector<int>> rec;
vector<ll> sz;

void f(int x, int v){
    sz[x]=v;
    if(inp[x]==-1) return;
    int v1=rec[inp[x]][0],v2=rec[inp[x]][1];
    if(sz[v1]==-1||sz[v2]==-1) return;
    if(v2) f(rec[inp[x]][2],sz[v1]+sz[v2]);
    else{
        f(rec[inp[x]][2],(sz[v1]+1)/2);
        f(rec[inp[x]][3],sz[v1]/2);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n,q,m;
    cin>>m>>n>>q;
    
    vector<pair<int,int>> par(10*n+1,{-1,-1});
    inp.assign(10*n+1,-1);
    rec.assign(n+1,{});
    sz.assign(10*m+1,-1);
    for(int i=0;i<n;i++){
        char p;
        int x,y,z;
        cin>>p>>x>>y>>z;
        if(p=='S'){
            par[y]={x,-1};
            par[z]={-1,x};
            inp[x]=i;
            rec[i]={x,0,y,z};
        }
        else {
            par[z]={x,y};
            inp[x]=inp[y]=i;
            rec[i]={x,y,z,0};
        }
    }
    sz[0]=0;
    f(1,m);
    
    for (int i = 2; i < 10 * n; ++i) if (sz[i] == -1) {
        f(i, 0);
    }

    while(q--){
        ll u,k;
        cin>>u>>k;
        int f=1;
        while(u!=1){
            int x=par[u].first;
            int y=par[u].second;
            if(k>sz[u]){
                f=0;
                break;
            }
            if(x==-1){
                u=y;
                k=2LL*k;
            }   
            else if(y==-1){
                u=x;
                k=2LL*k-1LL;
            }
            else{
                ll a=sz[x];
                ll b=sz[y];
                if(k>a+b){
                    f=0;
                    break;
                }
                if(a>=b){
                    if(k<=2LL*b){
                        if(k%2) u=x;
                        else u=y;
                        k=(k+1LL)/2;
                    }
                    else{
                        u=x;
                        k=k-b;
                    }
                }
                else{
                    if(k<=2LL*a){
                        if(k%2) u=x;
                        else u=y;
                        k=(k+1LL)/2;
                    }
                    else{
                        u=y;
                        k=k-a;
                    }
                }
            }
        }
        if(k>m) f=0;
        if(!f) cout<<"none\n";
        else cout<<k<<"\n";
    }



}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3400kb

input:

5 8 26
M 8 9 13
S 2 4 5
S 1 2 3
M 6 5 8
S 4 9 10
S 10 14 15
S 3 6 7
S 7 11 12
2 3
2 4
3 2
3 3
4 2
4 3
5 1
5 2
6 1
6 2
7 1
7 2
8 2
8 3
9 1
9 2
10 1
10 2
11 1
11 2
12 1
13 3
13 4
14 1
14 2
15 1

output:

5
none
4
none
5
none
3
none
2
none
4
none
3
none
1
none
5
none
4
none
none
3
none
5
none
none

result:

ok 26 lines

Test #2:

score: -100
Dangerous Syscalls

input:

1000000000 8191 1000
S 1 2 3
S 2 4 5
S 3 6 7
S 4 8 9
S 5 10 11
S 6 12 13
S 7 14 15
S 8 16 17
S 9 18 19
S 10 20 21
S 11 22 23
S 12 24 25
S 13 26 27
S 14 28 29
S 15 30 31
S 16 32 33
S 17 34 35
S 18 36 37
S 19 38 39
S 20 40 41
S 21 42 43
S 22 44 45
S 23 46 47
S 24 48 49
S 25 50 51
S 26 52 53
S 27 54 55...

output:


result: