QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95052#5110. SplitstreammarcoskWA 2ms5404kbC++172.0kb2023-04-09 01:18:482023-04-09 01:18:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-09 01:18:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5404kb
  • [2023-04-09 01:18:48]
  • 提交

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){
			cout<<"split "<<pos+1<<" in "<<to[pos].fst+1<<" "<<to[pos].snd+1<<"\n";
			am[to[pos].fst]+=(am[pos]+1)/2;
			am[to[pos].snd]+=am[pos]/2;
		}
		else if(to[pos].fst){
			cout<<"merge "<<pos+1<<" to "<<to[pos].fst+1<<"\n";
			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: 0
Wrong Answer
time: 2ms
memory: 5404kb

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:

split 1 in 2 3
split 2 in 4 5
split 3 in 6 7
split 4 in 9 10
merge 5 to 8
merge 6 to 8
split 7 in 11 12
merge 9 to 13
split 10 in 14 15
merge 8 to 13
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:

wrong answer 1st lines differ - expected: '5', found: 'split 1 in 2 3'