update
This commit is contained in:
		
							parent
							
								
									2d3a3ce03b
								
							
						
					
					
						commit
						3eff188a70
					
				
							
								
								
									
										
											BIN
										
									
								
								src/CSP-S2020/2020-CSP-S2.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/CSP-S2020/2020-CSP-S2.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										56
									
								
								src/P5854/P5854.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/P5854/P5854.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <istream>
 | 
				
			||||||
 | 
					#include <ostream>
 | 
				
			||||||
 | 
					#include <stack>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef ONLINE_JUDGE
 | 
				
			||||||
 | 
					    #define DEBUG(code)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    #define DEBUG(code)code
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using ll = long long;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const ll max_n = 1e7+5;
 | 
				
			||||||
 | 
					struct Node{
 | 
				
			||||||
 | 
					    ll left_child, right_child, val;
 | 
				
			||||||
 | 
					    friend std::ostream& operator<<(std::ostream &os, const Node &n){
 | 
				
			||||||
 | 
					        os<<"Node { val: "<<n.val<<", left_child: "<<n.left_child<<", right_child: "<<n.right_child<<" }";
 | 
				
			||||||
 | 
					        return os;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}nodes[max_n];
 | 
				
			||||||
 | 
					ll n;
 | 
				
			||||||
 | 
					std::stack<ll> stk;
 | 
				
			||||||
 | 
					ll root, ans1, ans2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(){
 | 
				
			||||||
 | 
					    std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cin>>n;
 | 
				
			||||||
 | 
					    for(ll i{1};i<=n;i++){
 | 
				
			||||||
 | 
					        std::cin>>nodes[i].val;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for(ll i{1};i<=n;i++){
 | 
				
			||||||
 | 
					        while(!stk.empty() && nodes[i].val < nodes[stk.top()].val){
 | 
				
			||||||
 | 
					            nodes[i].left_child = stk.top();
 | 
				
			||||||
 | 
					            stk.pop();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if(!stk.empty()){
 | 
				
			||||||
 | 
					            nodes[stk.top()].right_child = i;
 | 
				
			||||||
 | 
					        }else{
 | 
				
			||||||
 | 
					            root = i;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        stk.push(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    DEBUG(
 | 
				
			||||||
 | 
					        std::cout<<root<<'\n';
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    for(ll i{1};i<=n;i++){
 | 
				
			||||||
 | 
					        DEBUG(
 | 
				
			||||||
 | 
					            std::cout<<nodes[i]<<'\n';
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        ans1 ^= i * (nodes[i].left_child + 1);
 | 
				
			||||||
 | 
					        ans2 ^= i * (nodes[i].right_child + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    std::cout<<ans1<<' '<<ans2<<'\n';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user