fork download
  1. /**********************************************************************************/
  2. /* Problem: z033 "吃點心" from 2017 NPSC 國中組初試 */
  3. /* Language: C++ */
  4. /* Result: AC (750ms, 17573KB) on ZeroJudge */
  5. /* Author: cutecpu at 2019-04-22 20:17:32 */
  6. /**********************************************************************************/
  7.  
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10. #include<map>
  11.  
  12. #define MAXN 1000000
  13.  
  14. long long hash[MAXN + 1],total,stat;
  15.  
  16. int main(){
  17.  
  18. int N,A;
  19.  
  20. std::map<long long int,int> cnt;
  21.  
  22. scanf("%d",&N);
  23.  
  24. for(int i = 1; i <= MAXN; ++i) hash[i] = rand() | ((long long int) rand() << 32);
  25.  
  26. cnt[0] = 1;
  27. for(int i = 1; i <= N ; ++i){
  28. scanf("%d",&A);
  29. stat ^= hash[A];
  30. total += cnt[stat]++;
  31. }
  32.  
  33. printf("%lld\n",total);
  34.  
  35. return 0;
  36. }
Time limit exceeded #stdin #stdout 5s 23048KB
stdin
Standard input is empty
stdout
Standard output is empty