A Statistical Framework of Watermarks for Large Language Models: Pivot, Detection Efficiency and Optimal Rules