How to get raw unwritten querystring

$_GET refers literally to ?p=1 part of URL. With pretty permalink if it’s empty then there is nothing to access.

WordPress processed either case into query variables of WP_Query class. You should use get_query_var() to retrieve things like this, so in this specific case it would probably be get_query_var( 'p' ).