QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95053 | #5110. Splitstream | marcosk | WA | 5ms | 3880kb | C++17 | 1.9kb | 2023-04-09 01:19:29 | 2023-04-09 01:19:31 |
Judging History
answer
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int MAXN=1e5+10;
int wh[MAXN],in[MAXN],am[MAXN];
ii par[MAXN],to[MAXN];
int main(){FIN;
ll m,n,q; cin>>m>>n>>q;
string s(n,'.');
int k=1;
fore(i,0,n){
char c; int x,y,z; cin>>c>>x>>y>>z;
k=max({k,x,y,z});
x--; y--; z--;
s[i]=c;
if(c=='S'){
to[x]={y,z};
wh[y]=0; wh[z]=0;
in[y]++; in[z]++;
par[y]={x,0};
par[z]={x,1};
}
else{
to[x]={z,0};
to[y]={z,0};
wh[z]=1;
in[z]++;
par[z]={x,y};
}
}
queue<int> qq;
qq.push(0); am[0]=m;
while(SZ(qq)){
int pos=qq.front(); qq.pop();
if(to[pos].snd){
am[to[pos].fst]+=(am[pos]+1)/2;
am[to[pos].snd]+=am[pos]/2;
}
else if(to[pos].fst){
am[to[pos].fst]+=am[pos];
}
if(to[pos].fst){
in[to[pos].fst]--;
if(!in[to[pos].fst]) qq.push(to[pos].fst);
}
if(to[pos].snd){
in[to[pos].snd]--;
if(!in[to[pos].snd]) qq.push(to[pos].snd);
}
}
while(q--){
int x,k; cin>>x>>k; x--;
int bad=0;
while(!bad){
if(am[x]<k){
bad=1;
}
else if(x==0){
break;
}
else if(wh[x]==0){
if(par[x].snd==0) k=2*k-1;
else k=2*k;
x=par[x].fst;
}
else{
int l=par[x].fst, r=par[x].snd;
int asd=2*min(am[l],am[r]);
if(k<=asd){
if(k&1) k=(k+1)/2, x=par[x].fst;
else k=k/2, x=par[x].snd;
}
else if(am[l]>am[r]){
k=asd/2 + (k-asd);
x=par[x].fst;
}
else{
k=asd/2 + (k-asd);
x=par[x].snd;
}
}
}
if(bad)cout<<"none\n";
else cout<<k<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3476kb
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: 0
Accepted
time: 4ms
memory: 3880kb
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:
1 3 999999999 499999999 333333331 999999997 499999997 333333329 2 4 1000000000 500000000 333333332 999999998 499999998 333333330 1 5 999999997 499999997 333333329 999999993 499999993 333333325 3 7 999999999 499999999 333333331 999999995 499999995 333333327 2 6 999999998 499999998 333333330 999999994...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
1000000000 8190 1000 S 1 2 3 M 8193 8194 8192 S 2 4 5 M 8195 8196 8193 S 3 6 7 M 8197 8198 8194 S 4 8 9 M 8199 8200 8195 S 5 10 11 M 8201 8202 8196 S 6 12 13 M 8203 8204 8197 S 7 14 15 M 8205 8206 8198 S 8 16 17 M 8207 8208 8199 S 9 18 19 M 8209 8210 8200 S 10 20 21 M 8211 8212 8201 S 11 22 23 M 821...
output:
1 2 1000000000 500000000 333333333 999999999 499999999 333333332 1 1 3 3 999999999 999999999 499999999 499999999 333333331 333333331 999999997 999999997 499999997 499999997 333333329 333333329 2 2 4 4 1000000000 1000000000 500000000 500000000 333333332 333333332 999999998 999999998 499999998 4999999...
result:
ok 1000 lines
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 3776kb
input:
1000000000 10000 1000 S 1 2 3 S 2 4 5 S 4 6 7 S 6 8 9 S 8 10 11 S 10 12 13 S 12 14 15 S 14 16 17 S 16 18 19 S 18 20 21 S 20 22 23 S 22 24 25 S 24 26 27 S 26 28 29 S 28 30 31 S 30 32 33 S 32 34 35 S 34 36 37 S 36 38 39 S 38 40 41 S 40 42 43 S 42 44 45 S 44 46 47 S 46 48 49 S 48 50 51 S 50 52 53 S 52 ...
output:
1 1 536870913 none 2 none 3 none 4 none 5 none 6 none 7 none 8 none 9 none 10 none 11 none 12 none 13 none 14 none 15 none 16 none 17 none 18 none 19 none 20 none 21 none 22 none 23 none 24 none 25 none 26 none 27 none 28 none 29 none 30 none 31 none 32 none 33 none 34 none 35 none 36 none 37 none 3...
result:
wrong answer 4th lines differ - expected: '1000000000', found: 'none'