QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386704#5110. SplitstreamEnergy_is_not_over#RE 0ms3736kbC++172.7kb2024-04-11 19:30:362024-04-11 19:30:36

Judging History

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

  • [2024-04-11 19:30:36]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3736kb
  • [2024-04-11 19:30:36]
  • 提交

answer

//
// Stvoreno ENERGom o 11.04.24. 13:07:56
//

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define F first
#define fir first
#define S second
#define sec second
#define mp make_pair
#define MP make_pair
#define pb push_back
#define PB push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

#ifdef Energy
#define DEBUG for (int _____DEBUG=1;_____DEBUG;_____DEBUG=0)

template<class ...Ts>
auto &PRNT(Ts ...ts) { return ((cerr << ts << " "), ...); }

#define LOG(...) PRNT(#__VA_ARGS__" ::",__VA_ARGS__)<<endl
#else
#define DEBUG while (0)
#define LOG(...)
#endif

const int max_n = 1e4+10, inf = 1000111222;

pair<int,pii> ttt[max_n];

int m,n,q;

int lll[max_n];
bool calculated[max_n];

int get_lll(int id)
{
    if (calculated[id]==1){
        return lll[id];
    }

    if (ttt[id].fir==1){
        int was=get_lll(ttt[id].sec.fir);
        calculated[id]=1;
        return lll[id]=(ttt[id].sec.sec==1?was/2:was-was/2);
    }
    else{
        calculated[id]=1;
        return lll[id]=get_lll(ttt[id].sec.fir)+get_lll(ttt[id].sec.sec);
    }
}

int get_res(int id,int k)
{
    if (k>get_lll(id)){
        return -1;
    }
    if (id==1){
        return k;
    }

    if (ttt[id].fir==1){
        const int id_there=(ttt[id].sec.sec==0 ? 2*k-1 : 2*k);
        return get_res(ttt[id].sec.fir,id_there);
    }
    else{
        int mn=min(get_lll(ttt[id].sec.fir),get_lll(ttt[id].sec.sec));
        if (k<=2*mn){
            if (k%2==0){
                return get_res(ttt[id].sec.sec,k/2);
            }
            else{
                return get_res(ttt[id].sec.fir,(k+1)/2);
            }
        }
        else{
            const int from_whom=get_lll(ttt[id].sec.fir)<get_lll(ttt[id].sec.sec)?ttt[id].sec.sec:ttt[id].sec.fir;
            return get_res(from_whom,mn+(k-2*mn));
        }
    }
}

int main() {
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>m>>n>>q;
    for (int i=0;i<n;i++){
        char type;
        cin>>type;
        int x,y,z;
        cin>>x>>y>>z;
        if (type=='S'){
            ttt[y]=mp(1,mp(x,0));
            ttt[z]=mp(1,mp(x,1));
        }
        else if (type=='M'){
            ttt[z]=mp(2,mp(x,y));
        }
        else{
            assert(0);
        }
    }
    lll[1]=m;
    calculated[1]=1;
    for (int i=0;i<q;i++){
        int id,k;
        cin>>id>>k;
        int res=get_res(id,k);
        if (res==-1){
            cout<<"none"<<"\n";
        }
        else{
            cout<<res<<"\n";
        }
    }

    exit(0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

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
Runtime Error

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: